Thread overview |
---|
July 30, 2017 Is std.xml seriously broken, or is it me? | ||||
---|---|---|---|---|
| ||||
I'm trying to use std.xml, and I can't get it to work. I tried the simplest program I could think of: import std.xml; import std.stdio; void main() { auto parser = new DocumentParser("<?xml version=\"1.0\" encoding=\"utf-8\"?><device></device>"); parser.onStartTag["device"] = (ElementParser parser) { writeln("device"); }; parser.parse(); } https://dpaste.dzfl.pl/262597d2fda6 I used it before without any trouble. Is it somehow seriously broken? If not, what am I doing wrong? Thanks, Mike |
July 30, 2017 Re: Is std.xml seriously broken, or is it me? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike | On Sunday, 30 July 2017 at 02:58:09 UTC, Mike wrote: > import std.xml; > import std.stdio; > > void main() > { > auto parser = new DocumentParser("<?xml version=\"1.0\" encoding=\"utf-8\"?><device></device>"); > parser.onStartTag["device"] = (ElementParser parser) > { > writeln("device"); > }; > parser.parse(); > } > > https://dpaste.dzfl.pl/262597d2fda6 > > I used it before without any trouble. Is it somehow seriously broken? If not, what am I doing wrong? It appears `onStartTag` does not handle the root element. For example, this code seems to work: import std.xml; import std.stdio; void main() { auto parser = new DocumentParser("<?xml version=\"1.0\" encoding=\"utf-8\"?><device><peripheral></peripheral></device>"); parser.onStartTag["peripheral"] = (ElementParser parser) { writeln("peripheral"); }; parser.parse(); } Mike |
July 30, 2017 Re: Is std.xml seriously broken, or is it me? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike | On Sunday, 30 July 2017 at 02:58:09 UTC, Mike wrote: > I'm trying to use std.xml, and I can't get it to work. > > I tried the simplest program I could think of: > > import std.xml; > import std.stdio; > > void main() > { > auto parser = new DocumentParser("<?xml version=\"1.0\" encoding=\"utf-8\"?><device></device>"); > parser.onStartTag["device"] = (ElementParser parser) > { > writeln("device"); > }; > parser.parse(); > } > > https://dpaste.dzfl.pl/262597d2fda6 > > I used it before without any trouble. Is it somehow seriously broken? If not, what am I doing wrong? > > Thanks, > Mike I don't know about your code specifically, but std.xml has been on the chopping block for many years and is pretty much still around because nobody has written a replacement yet. I'd recommend using Adam Ruppe's DOM library instead: https://github.com/adamdruppe/arsd/blob/master/dom.d |
July 30, 2017 Re: Is std.xml seriously broken, or is it me? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike | On Sunday, 30 July 2017 at 03:16:35 UTC, Mike wrote: > On Sunday, 30 July 2017 at 02:58:09 UTC, Mike wrote: > >> [...] > > It appears `onStartTag` does not handle the root element. For example, this code seems to work: > > import std.xml; > import std.stdio; > > void main() > { > auto parser = new DocumentParser("<?xml version=\"1.0\" encoding=\"utf-8\"?><device><peripheral></peripheral></device>"); > parser.onStartTag["peripheral"] = (ElementParser parser) > { > writeln("peripheral"); > }; > parser.parse(); > } > > Mike You may want to try the experimental candidate for Phobos instead, which was developed as a GSoC project but never finished: http://code.dlang.org/packages/std-experimental-xml |
July 31, 2017 Re: Is std.xml seriously broken, or is it me? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mike | On Sunday, 30 July 2017 at 03:16:35 UTC, Mike wrote:
> It appears `onStartTag` does not handle the root element.
Looks like a bug. Until the module is replaced, bug reports are still accepted for it.
|
Copyright © 1999-2021 by the D Language Foundation