XML D2.x parsing &
Jesse Phillips
jessekphillips+d at gmail.com
Mon Jul 20 12:43:58 PDT 2009
According to the documentation having & in a tag will be turned to &
http://digitalmars.com/d/2.0/phobos/std_xml.html#text
I observe that this is not the case. And if an attribute contains & it is turned into & What is the best way to receive the same output for both. The code that follows outputs
Attr: What & Up
Elem: What & Up
*testfile.xml:*
<?xml version="1.0" encoding="utf-8"?>
<Tests>
<Test thing="What & Up">What & Up</Test>
</Tests>
*test.d:*
import std.stdio;
import std.xml;
void main() {
auto file = "testfile.xml";
auto s = cast(string)std.file.read(file);
auto xml = new DocumentParser(s);
xml.onStartTag["Test"] = (ElementParser xml) {
writeln("Attr: ", xml.tag.attr["thing"]);
};
xml.onEndTag["Test"] = (in Element e) {
writeln("Elem: ", e.text);
};
xml.parse();
}
More information about the Digitalmars-d-learn
mailing list