why do I receive an empty document [#document: null] when I read a xml file with xmlread?

I tried to read a simple xml file {<rows> <row id='0'> <cell>65</cell> </row> <row id='1'> <cell>565</cell> </row> <row id='2'> <cell>6565</cell> </row></rows>} and received [#document: null].

 採用された回答

Robert Snoeberger
Robert Snoeberger 2015 年 12 月 19 日
編集済み: Robert Snoeberger 2015 年 12 月 19 日
I'm not sure why you think that you received an empty document.
The display that you are seeing, [#document: null], consists of two parts. The first part is #document, which is the node name. When you parse XML with xmlread, you always receive a #document node as the top-level node.
>> dom = xmlread('example.xml')
dom =
[#document: null]
>> getNodeName(dom)
ans =
#document
>>
The second part is null, which is the value of the node. null is used to indicate that the node doesn't have a value.
>> getNodeValue(dom)
ans =
[]
>>
A #text node usually has a value. In your example, the text node under the first cell element has a value of '65'.
>> cells = dom.getElementsByTagName('cell');
>> cell = cells.item(0)
cell =
[cell: null]
>> text = cell.item(0)
text =
[#text: 65]
>> getNodeValue(text)
ans =
65
>>

4 件のコメント

Siahlo Ivan
Siahlo Ivan 2015 年 12 月 20 日
Thank you for the answer. The question was stupid. I had to read more help. I know a little about DOM and found later the answer. However, your answer is useful for me. Now I understand better the logic of Matlab. I'm new in Matlab and document:null disturbed me. I saw that the file was read and I could not understand why document was null.
SimonD
SimonD 2017 年 10 月 23 日
Me too - this was useful - thank you!
YUNA PARK
YUNA PARK 2019 年 5 月 30 日
Thanks! This was really helpful to me!
Runzhi Jiao
Runzhi Jiao 2020 年 7 月 11 日
Very good answer! a lot help for me! thanks a lot!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeData Type Identification についてさらに検索

製品

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by