Reading XMl and filtering through the notes

4 次查看(过去 30 天)
Hello,
Given that much isn't visible when trying to use the node structure in Matlab I am finding it hard to go visualise what I'm doing. It would porbbaly be easier to do in Java!
My issue it probably a simple one to resolve but strugling to get it right. I have the
XML script:
<Assumptions>
<Scalar>
<AsOfDate>
<XAxis>'AsOfDate'</XAxis>
<YAxis>85000</YAxis>
</AsOfDate>
<Misc>
<XAxis>'Misc'</XAxis>
<YAxis>1.0</YAxis>
</Misc>
</Scalar>
<D1>
<FTB>
<XAxis>{1,2,3}</XAxis>
<YAxis>{0.1,0.2,0.3}</YAxis>
</FTB>
</D1>
</Assumptions>
I've tried to use xPath although I think given the structure is fairly simple I just need to cycle through each of the nodes and pull out the relevant values.
% get the xpath mechanism into the workspace
import javax.xml.xpath.*
factory = XPathFactory.newInstance;
xpath = factory.newXPath;
% compile and evaluate the XPath Expression
expression = xpath.compile('Assumptions/Scalar');%'AddressBook/Entry');
ScalarNodes = expression.evaluate(Assumptions, XPathConstants.NODESET);
AsOfNode = ScalarNodes.item(0).getChildNodes;
AsOfNode.getTextContent
XNode = AsOfNode.item(0);
XNode.getTextContent
This code was more to try to visualise the outputs.
AsOfNode.getTextContent
In the instance above it gives me the information in Node AsOfDate and Mis. However I don't understand why I get get the information from each node as tried below:
XNode.getTextContent
Maybe I'm constructing incorrectly but I can't get my head around. Essentially I want to go through every node to get the structure as follows:
Within which i have another struct
This struct would have the name of the field and the value

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Structured Data and XML Documents 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by