V-REP教程(四)XML

http://www.w3school.com.cn/xml/xml_intro.asp 参考自w3cschool,作者精简。
1.XML(EXtensible Markup Language) 被设计用来结构化、存储以及传输信息。
举例:

//John 写给 George 的便签,存储为 XML
<note>
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>

注释:XML 文档是一种树结构,它从“根部”开始,然后扩展到“枝叶”。
描述根元素,像在说:“本文档是一个便签”;
接下来 4 行描述根的 4 个子元素(to, from, heading 以及 body);
最后一行定义根元素的结尾:</note>
如何用XML来存储书店里的书籍信息?
可将bookstore作为根元素,book作为叶,每个book又包括了title,author,year,price,同时考虑到分类,必须给每个book增添附加信息即分类依据
如:<book category="CHILDREN"> //<book> 元素拥有属性 (category="CHILDREN")

<bookstore>
<book category="COOKING">
  <title lang="en">Everyday Italian</title> 
  <author>Giada De Laurentiis</author> 
  <year>2005</year> 
  <price>30.00</price> 
</book>
<book category="CHILDREN">
  <title lang="en">Harry Potter</title> 
  <author>J K. Rowling</author> 
  <year>2005</year> 
  <price>29.99</price> 
</book>
<book category="WEB">
  <title lang="en">Learning XML</title> 
  <author>Erik T. Ray</author> 
  <year>2003</year> 
  <price>39.95</price> 
</book>
</bookstore>

2.XML 允许创作者定义自己的标签和自己的文档结构。

上例中的标签没有在任何 XML 标准中定义过。这些标签是由文档的创作者发明的。
这是因为 XML 没有预定义的标签。
3.用途·:通过使用几行 JavaScript,你就可以读取一个外部 XML 文件,然后更新 HTML 中的数据内容。
这里写图片描述
4.属性通常提供不属于数据组成部分的信息。在下面的例子中,文件类型与数据无关,但是对需要处理这个元素的软件来说却很重要:

<file type="gif">computer.gif</file>

ID属性
<messages>
<note id="501">
<to>George</to>
<from>John</from>
<heading>Reminder</heading>
<body>Don't forget the meeting!</body>
</note>
<note id="502">
<to>John</to>
<from>George</from>
<heading>Re: Reminder</heading>
<body>I will not</body>
</note>
</messages>
<!-- ID 仅仅是一个标识符,用于标识不同的便签。它并不是便签数据的组成部分。
在此我们极力向您传递的理念是:元数据(有关数据的数据)应当存储为属性,而数据本身应当存储为元素。-->

5.注意点
XML 文档必须有根元素
XML 文档必须有关闭标签
XML 标签对大小写敏感
XML 元素必须被正确的嵌套
XML 属性必须加引号

6.看懂Vrep中的UI
The custom UI plugin 是基于QT的,源代码可以在 programming/v_repExtCustomUI.文件中查看;

xml的作用是存储和向QT插件传输信息,内容包含在xml = [[ ]] 中,查看file:///F:/V-REP3/V-REP_PRO_EDU/helpFiles/index.html可知包含如下元素<ui> <button> <checkbox> <combobox> <edit> <group> <hslider> <image> <label> <plot> <radiobutton> <spinbox> <tabs> <tab> <vslider> <stretch> <br>

xml = [[
<ui closeable="true" onclose="closeEventHandler" resizable="true">
//ui表示根,closeable是属性……
    <label text="Car control pan" wordwrap="true" />
    //定义了一个label叶……
    <group>//对不同元素和显示的文本分组,分组是为了布局,分组1
        <label text="Simulation time:" id = "999"  wordwrap="false" />      
    </group>
    <group>//分组2
        <label text="State:init" id = "1000" wordwrap="true" />
        <button text="Start move"  onclick = "Start_move" />
        //按钮    
    </group>
    <group>//分组3
        <label text="IK_flag:off" id = "1010" wordwrap="true" />
        <radiobutton text="Loosen" onclick="radiobuttonClick" id="1011" />
        //单选框
        <radiobutton text="Grasp" onclick="radiobuttonClick" id="1012" checked = 'true' />
        <button text="IK_on" onclick = "IK_on" />
    </group>    
</ui>
]]

效果如下:
这里写图片描述

7.补充

<lf>用于换行  linefeed

这里写图片描述

猜你喜欢

转载自blog.csdn.net/danieldingshengli/article/details/80581346
今日推荐