필터 지우기
필터 지우기

Reading XMl and filtering through the notes

조회 수: 4 (최근 30일)
Stephan Richtering
Stephan Richtering 2015년 11월 6일
편집: Walter Roberson 2015년 11월 7일
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