tinyxml:快速入门----一个官方带说明示例的翻译

转自Tinyxml主页上的一部分:


How TinyXML works.
TinyXML如何工作的


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:

这并不是一个很好的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"


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值