Re: kxml - parsing AWS API xml respond

2015-10-21 Thread opticron via Digitalmars-d-learn
On Tuesday, 20 October 2015 at 16:53:19 UTC, holo wrote: When im checking instance name with such code: auto test = list.parseXPath(`//tagSet/item[key="Name"]/value`)[0].goCData; it is compiling properly but it is breaking program when is no name set. I make quick workaround:

Re: kxml - parsing AWS API xml respond

2015-10-20 Thread Kagamin via Digitalmars-d-learn
You can write a helper: XmlNode selectSingleNode(XmlNode src, string path) { XmlNode[] nodes = src.parseXPath(path); return nodes.length==0 ? null : nodes[0]; } Then: string test1 = node.selectSingleNode(`//instanceId`).getCData();

Re: kxml - parsing AWS API xml respond

2015-10-20 Thread holo via Digitalmars-d-learn
On Tuesday, 20 October 2015 at 13:23:47 UTC, opticron wrote: I think part of the issue here is that holo isn't quite sure of what information [s]he needs out of the XML reply and how to do that with XPath. The first post mentioned getting instanceId and launchTime, so I'll start there using

Re: kxml - parsing AWS API xml respond

2015-10-20 Thread opticron via Digitalmars-d-learn
I think part of the issue here is that holo isn't quite sure of what information [s]he needs out of the XML reply and how to do that with XPath. The first post mentioned getting instanceId and launchTime, so I'll start there using the AWS example XML found here:

Re: kxml - parsing AWS API xml respond

2015-10-19 Thread Kagamin via Digitalmars-d-learn
Select parent tags and get data from their child tags like instanceId.

Re: kxml - parsing AWS API xml respond

2015-10-19 Thread holo via Digitalmars-d-learn
On Monday, 19 October 2015 at 11:53:08 UTC, Kagamin wrote: On Monday, 19 October 2015 at 04:49:25 UTC, holo wrote: Why there is needed that "//" before tag? That's an XPath expression. Need, to read about that XPaths. How to drop tags from respond? I have such result of parsing by id

Re: kxml - parsing AWS API xml respond

2015-10-19 Thread holo via Digitalmars-d-learn
Sorry i was trying to use that XPaths to take out instanceId and laounchTime but i always get an empty respond. //instanceId/launchTime" - empty //instanceId/* - empty too //instanceId.launchTime - empty too How to take instance id and variable which im interest in or few/all for

Re: kxml - parsing AWS API xml respond

2015-10-19 Thread Kagamin via Digitalmars-d-learn
On Monday, 19 October 2015 at 04:49:25 UTC, holo wrote: Why there is needed that "//" before tag? That's an XPath expression. How to drop tags from respond? I have such result of parsing by id tag: i-xx I need only value. Is there some equivalent to ".text" from std.xml? Try

Re: kxml - parsing AWS API xml respond

2015-10-19 Thread holo via Digitalmars-d-learn
On Monday, 19 October 2015 at 12:54:52 UTC, Kagamin wrote: Select parent tags and get data from their child tags like instanceId. void main() { string xmlstring = cast(string)read("test.xml"); XmlNode newdoc = xmlstring.readDocument(); XmlNode[] searchlist =

Re: kxml - parsing AWS API xml respond

2015-10-19 Thread Kagamin via Digitalmars-d-learn
If you don't want parent tag, then: XmlNode[] searchlist2 = newdoc.parseXPath("//launchTime");

Re: kxml - parsing AWS API xml respond

2015-10-19 Thread holo via Digitalmars-d-learn
On Monday, 19 October 2015 at 16:12:56 UTC, Kagamin wrote: If you don't want parent tag, then: XmlNode[] searchlist2 = newdoc.parseXPath("//launchTime"); I wanted parent tag, i think. I almost figure out what i needed, but getCData stops working :/ void main() { string xmlstring =

Re: kxml - parsing AWS API xml respond

2015-10-19 Thread holo via Digitalmars-d-learn
I have no idea what i'm doing, but i did it (i just choose 1 element of array): void main() { string xmlstring = cast(string)read("test.xml"); XmlNode newdoc = xmlstring.readDocument(); XmlNode[] searchlist = newdoc.parseXPath(`//instancesSet/item`); foreach(list;