1. MATLAB 自带的 xmlread,xmlwrite
1.1 函数和方法简介
xmlread
Read XML document and return Document Object Model node
Syntax:DOMnode= xmlread(lename) %reads the specied XML le and returns
a Document Object Model node representing the document
xmlwrite
Write XML Document Object Model node
Syntax:xmlwrite(lename,DOMnode) %writes the Document Object Model
(DOM) node DOMnode to the le lename
str = xmlwrite(DOMnode) %serializes the DOM node to a string
可以看到,在 MATLAB 中,使用 xmlread 读取 XML 文件,输出一个表示此 XML 结构的文档
对象模型(Document Object Model,缩写 DOM)节点,然后对 XML 文件的操作都要转化为对
DOM 节点的操作,最后使用 xmlwrite 把 DOM 节点写入到 xml 文件中。
DOM 是表示和处理一个 HTML 或 XML 文档的常用方法,它可以以一种独立于平台和语言的方
式访问和修改一个文档的内容和结构。关于 DOM 的资料在网上很多,xmlread 的帮助文档里也有
涉及。DOM 节点的操作方法都在 http://download.oracle.com/javase/6/docs/api/org/w3c/
dom/package-summary.html,下面列举一些常用的方法。
Document
Element getDocumentElement()
This is a convenience attribute that allows direct access to the child node
that is the document element of the document.
String getXmlVersion()
An attribute specifying, as part of the XML declaration, the version
number of this document.
Void setXmlVersion(String xmlVersion)
An attribute specifying, as part of the XML declaration, the version
number of this document.
Element
NodeList getElementsByTagName(String name)
Returns a NodeList of all descendant Elements with a given tag name, in
document order.
Element createElement(String tagName)
Creates an element of the type specied.
Node
String getNodeName()
The name of this node, depending on its type;
String getTextContent()
This attribute returns the text content of this node and its descendants.
Void setTextContent(String textContent)