Support for "empty" tags
QueenOfSquiggles opened this issue · 2 comments
Hello! I am working on a project where I'm modelling data in XML. Here's a mockup of how I'd like the data to present:
<?xml version="1.0"?>
<c11r>
<godot uid="02123"/>
<dependencies>
<res guid="02165+" path="res://asdaslkhjasd"/>
</dependencies>
</c11r>
now as per proper XML schema the godot
and res
tags wold be considered empty, but I'm targeting their attributes for the data that I need since it's fairly simple and then I can do an item-by-item parsing. When I try to parse with the reader it skips over these "empty" tags. And when I add the separate closing tags it sucessfully parses.
let mut bytes = data.as_bytes(); // data is String
let reader = ParserConfig::new()
.trim_whitespace(true)
.ignore_comments(true)
.coalesce_characters(true)
.create_reader(&mut bytes);
(For greater context, this is for a godot-rust based extension that registers a new language for scripting that I want to have as a visual scripting language, and XML seems the best way to store the data I want with the tag-attribute schema.)
I would appreciate support for "empty" (self-closing) tags, even if that requires a separate event. I'm not necessarily the best when it comes to rust but if it helps I could look into how this crate works and see if I can write the code for supporting this myself.
Empty tags are of course supported. However, XML explicitly says that <tag/>
and <tag></tag>
have exactly the same meaning, and both forms are allowed. It's a superficial syntactic detail, like use of "
or '
for quotes. So xml-rs will emit start and end event for empty tags, so that you can handle both syntaxes with the same code.
1:1 StartDocument(1.0, UTF-8)
2:1 StartElement(c11r)
3:5 StartElement(godot [uid="02123"])
3:5 EndElement(godot)
4:5 StartElement(dependencies)
5:9 StartElement(res [guid="02165+", path="res://asdaslkhjasd"])
5:9 EndElement(res)
6:5 EndElement(dependencies)
7:1 EndElement(c11r)
7:8 EndDocument
Sorry to waste time! I don't know what was happening wrong (likely I made a dumb mistake) but it wasn't emitting until I did a code refactor. Maybe I accidentally switched checking for StartElement
and StartDocument
. Thanks for your patience!