필터 지우기
필터 지우기

Issues trying to go through an example

조회 수: 2 (최근 30일)
Stephan Richtering
Stephan Richtering 2015년 11월 6일
댓글: cnfan_sd70 2019년 2월 7일
Hello, I'm trying the example on the first page from this url http://blogs.mathworks.com/community/2010/11/01/xml-and-matlab-navigating-a-tree/
I can't seem to get the first example to work:
% Get the "AddressBook" node
addressBookNode = docNode.getDocumentElement;
% Get all the "Entry" nodes
entries = addressBookNode.getChildNodes;
% Get the first "Entry"'s children
% Remember that java arrays are zero-based
friendlyInfo = entries.item(0).getChildNodes;
% Iterate over the nodes to find the "PhoneNumber"
% once there are no more siblinings, "node" will be empty
node = friendlyInfo.getFirstChild;
while ~isempty(node)
if strcmpi(node.getNodeName, 'PhoneNumber')
break;
else
node = node.getNextSibling;
end
end
phoneNumber = node.getTextContent
I get the following error:
No appropriate method, property, or field getFirstChild
for class org.apache.xerces.dom.CharacterDataImpl$1.
Any clue to why this happens?
Thanks, Stephan
  댓글 수: 1
Jack Latham
Jack Latham 2017년 1월 31일
I'm also having this issue - did you resolve it by any chance?

댓글을 달려면 로그인하십시오.

답변 (1개)

Chris
Chris 2017년 5월 10일
Try this: friendlyInfo = entries.item(1).getChildNodes;
It worked for me.
  댓글 수: 1
cnfan_sd70
cnfan_sd70 2019년 2월 7일
have tried your suggestion Chris and it returns no error. however when i do the next step:
>> node = friendlyInfo.getFirstChild
I get the following returned:
node =
[#text:
]
And
>> node.getNodeName
just returns:
#text
Anybody know why?
I have been performing this on the self same example xml that he gives in the article
Frankly this example needs to be updated because it doesn't work.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by