Dlang kxml getCData usage

83 Views Asked by At

I'm using in my project such library for XML parsing:

https://github.com/opticron/kxml/blob/master/source/kxml/xml.d

Here is my example code:

void main()
{
    string xmlstring = cast(string)read("test.xml");
    XmlNode newdoc = xmlstring.readDocument();
    XmlNode[]  searchlist = newdoc.parseXPath("//instancesSet/item");

    foreach(list, searchlist)
    {
    string test = list.parseXPath("//instanceId").getCData();
    writeln(test);
    }
}

And it don't want to compile:

$ dub
Performing "debug" build using dmd for x86_64.
kxml 1.0.0: target for configuration "library" is up to date.
test ~master: building configuration "application"...
source/app.d(23,56): Error: no property 'getCData' for type 'XmlNode[]'
dmd failed with exit code 1.

When I'm using foreach loop I thought it is taking only one value from whole array. So if that is array of XmlNode[] variable, only one from it should be just XmlNode (not array).

Why it still see there array? How to use getCData() method to clear variable from tags and put it to string?

1

There are 1 best solutions below

0
On

In the loop, list is in fact an XmlNode, but its parseXPath() returns XmlNode[]. If you want to work only with first result of XPath query in each list, just add [0].

string test = list.parseXPath("//instanceId")[0].getCData();