
Hi,
I try to read an xml-file and have problem to get the action attirbut:
The xml looks like this:
<?xml version="1.0" encoding="iso-8859-1"?>
<Product action="create" xmlns="http://www.test/formatimport">
<TitleCode>TTTT</TitleCode>
<Date>2012-04-26</Date>
<Edition>SI</Edition>
<SectionSizes>20</SectionSizes>
<Page>
<PageNumber>1</PageNumber>
<Colours>c m y k</Colours>
<Name>Etusivu</Name>
<Type>Etusivu</Type>
</Page>..........................
My Code is:
XMLDocument xmlDoc;
XMLNode rootNode;
XMLNode pageNodeRecord;
XMLNodeList salesLines, pageNodeList;
XMLParseError xmlError;
rootNode = xmlDoc.documentElement();
// Get the action attribut????
// Get information from nodes.
titlecode = rootNode.selectSingleNode("//TitleCode").text();
dat = rootNode.selectSingleNode("//Date").text();
My problem is that I cant get the attribut action="create" .
I tried different methods under rootNode and didnt find a way to get it.
Does somebody know how to do this??
Thanks for help.
*This post is locked for comments
I have the same question (0)The easiest option is to simply call rootNode.getAttribute('action').
Another option is to benefit from the fact that selectSingleNode() accepts XPath - you can get the value by calling rootNode.selectSingleNode('@action').value() or even xmlDoc.selectSingleNode('Product/@action).value(). XPath is really helpful in more complex scenarios.
You have even more ways, e.g. to use rootNode.attributes().getNamedItem('action').