kxml - parsing AWS API xml respond

opticron via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Oct 20 06:23:46 PDT 2015


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: 
https://github.com/polopoly/cloud-ui/blob/master/aws/examples/DescribeInstances.xml

You can find all parent nodes that provide this set of 
information with XPath query "//instancesSet/item". From there, 
you can iterate over the list and pull out the information you 
need:

auto parents = root.parseXPath("//instancesSet/item");
foreach(parent; parents) {
   string instanceId = 
parent.parseXPath("instanceId")[0].getCData();
   string launchTime = 
parent.parseXPath("launchTime")[0].getCData();
}

In the process of checking this out, I discovered that subnode 
predicates are broken (attribute predicates work just fine, I 
need to write more unittests). I guess I have some things to work 
on tonight.


More information about the Digitalmars-d-learn mailing list