原文链接如下:
http://www.grinninglizard.com/tinyxmldocs/index.html
在程序中使用tinyXML:
To Use in an Application:
使用tinyXML,只需将解压的文件,tinyxml.cpp,tinyxml.h,tinyxmlerror.cpp,tinyxmlparser.cpp,tinystr.cpp,and tinystr.h 加入到你的工程中去,就可以了。它可以编译于任何兼容c++的系统, TinyXML无须开启Exception和RTTI.
Add tinyxml.cpp,and tinystr.h to your project or make file. That’s it! It should compile on any reasonably compliant C++ system. You do not need to enable exceptions or RTTI for TinyXML.
TinyXML是如何工作的
How TinyXML works.
示例如下:
An example is probably the best way to go. Take:
<?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:
tixmlDocument doc( "demo.xml" );
doc.LoadFile();
加载文件以后,看一下文件中的行语句跟DOM之间的关系。
And its ready to go. Now lets look at some lines and how they relate to the DOM.
<?xml version="1.0" standalone=no>
demo.xml第一行是一个声明,被转化为tixmlDeclaration 类对象,是demo.xml的第一个子节点。
The first line is a declaration,and gets turned into the tixmlDeclaration class. It will be the first child of the document node.
这是TinyXML唯一一个特殊处理的标记,此标记存储在tixmlUnkNown类对象中,在写入硬盘时,不要忘了此命令。
This is the only directive/special tag parsed by TinyXML. Generally directive tags are stored in tixmlUnkNown so the commands wont be lost when it is saved back to disk.
<!-- Our to do list data -->
一句注释,将会转化为 tixmlComment 类对象。
A comment. Will become a tixmlComment object.
<Todo>
Todo标记定义了一个tixmlElement 对象,此标记没有任何的属性,但包含两个成员。
The “Todo” tag defines a tixmlElement object. This one does not have any attributes,but does contain 2 other elements.
<Item priority="1">
创建了一个Todo成员的子成员。这个成员包含一个属性,名字是”priority”,值是”1”。
Creates another tixmlElement which is a child of the “Todo” element. This element has 1 attribute,with the name “priority” and the value “1”.
Go to the
一个tixmlText对象,是一个叶节点,不能包含其它的子节点。是的 Item成员的孩子。
A tixmlText. This is a leaf node and cannot contain other nodes. It is a child of the “Item” tixmlElement.
<bold>
又一个Item成员的子成员。
Another tixmlElement,this one a child of the “Item” element.
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"
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。