tinyxml:快速入门----一个官方带说明示例的翻译
转自Tinyxml主页上的一部分:
How TinyXML works.
例子是最好的入门办法。例如: <?xml version="1.0" standalone=no> <!-- Our to do list data --> <ToDo> <Item priority="1"> Go to the <bold>Toy store!</bold></Item> <Item priority="2"> Do bills</Item> </ToDo> Its not much of a To Do list,but it will do. To read this file (say "demo.xml") you would create a document,and parse it in: 这并不是一个很好的To Do清单,但用来示例足够了。读取这个文件(且称为"demo.xml"),你需要创建一个document,然后用它来解析: TiXmlDocument doc( "demo.xml" ); doc.LoadFile();And its ready to go. Now lets look at some lines and how they relate to the DOM. 这样就准备好了。现在来看看一些代码,看他们如何跟DOM联系起来。 <?xml version="1.0" standalone=no> The first line is a declaration,and gets turned into theTiXmlDeclaration class. It will be the first child of the document node. 第一行是一个声明,生成TiXmlDeclaration对象。这是document的第一个孩子。 This is the only directive/special tag parsed by TinyXML. Generally directive tags are stored inTiXmlUnknown so the commands wont be lost when it is saved back to disk. 这是TinyXML解析的唯一一个directive tag。其他的directive tag存储在TiXmlUnknown,所以当他们存储到磁盘时,不会丢失。 <!-- Our to do list data --> A comment. Will become aTiXmlComment object. 这是注释。生成TiXmlComment对象。 <ToDo> The "ToDo" tag defines aTiXmlElement object. This one does not have any attributes,but does contain 2 other elements. To Do tag生成TiXmlElement对象。这个tag没有包含任何属性(attribute),但它包括两个元素(element) <Item priority="1"> Creates anotherTiXmlElement which is a child of the "ToDo" element. This element has 1 attribute,with the name "priority" and the value "1". 这是TiXmlElement元素,也是To Do元素的一个孩子。这个元素有一个属性,name是"priority",值是"1"。 Go to the A TiXmlText. This is a leaf node and cannot contain other nodes. It is a child of the "Item"TiXmlElement. 这是TiXmlText对象,这是一个叶节点,不包括其他子节点。这是"Item"的孩子。 <bold> Another TiXmlElement,this one a child of the "Item" element. 另一个TiXmlElement元素,是"item"的子节点 Etc. 等等。 Looking at the entire object tree,you end up with: 看看完整的对象树,你将得到: TiXmlDocument "demo.xml" TiXmlDeclaration "version='1.0'" "standalone=no" TiXmlComment " Our to do list data" TiXmlElement "ToDo" TiXmlElement "Item" Attribtutes: priority = 1 TiXmlText "Go to the " TiXmlElement "bold" TiXmlText "Toy store!" TiXmlElement "Item" Attributes: priority=2 TiXmlText "Do bills" (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |