English 中文(简体)
MATLAB: 查阅XML物体
原标题:MATLAB: accessing XML object
  • 时间:2011-11-15 00:57:43
  •  标签:
  • xml
  • matlab

在MATLAB中,I装载XML文档doc Node = xmlread(puff.xml );

<?xml version="1.0"?>
<rss version="2.0" xmlns:g="http://somesite.com">
    <channel>
        <title>Blah</title>
        <link>http://www.blah.com</link>
        <description>BLAH.COM </description>
        <item>    
            <link>http://www.blah.com/page</link>
        </item>
    </channel>
</rss>

I m试图在<link>中检索这一条,但事实证明它相当trick。 http://blogs.mathwork.com/desktop/ 是否有人想如何进入<代码><link>? TIA!

最佳回答

你们需要做些什么?

>> docNode = xmlread( stuff.xml );
>> l = docNode.getElementsByTagName( link );
>> char(l.item(0).getFirstChild.getData)
ans =
http://www.blah.com
>> char(l.item(1).getFirstChild.getData)
ans =
http://www.blah.com/page

PS 你在<代码>stuff.xml上有一处错误——该代码应为</channel>,而不是</<channel>


Edit:为了直接通过每个链接进行操作,可使用l.getLength:

for i = 0:(l.getLength - 1) % 0-based indexing, not 1-based like MATLAB arrays
    char(l.item(i).getFirstChild.getData)
end

ans =
http://www.blah.com
ans =
http://www.blah.com/page
问题回答

暂无回答




相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签