www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is std.xml seriously broken, or is it me?

reply Mike <none none.com> writes:
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
Jul 29
next sibling parent reply Mike <none none.com> writes:
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
Jul 29
next sibling parent Joakim <dlang joakim.fea.st> writes:
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
Jul 30
prev sibling parent Kagamin <spam here.lot> writes:
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.
Jul 31
prev sibling parent Meta <jared771 gmail.com> writes:
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
Jul 29