生成XML
我们也可以用XObject生成XML,和用JObject生成JSON的方法是一回事,只是前者用ToXML方法,后者用ToString方法。
示例一
在命令窗口执行:
Dim
jo As
New
Foxtable.XObject
jo("Name")
= "张三"
jo("Group")
= "VIP"
jo("Type")
= 2
jo("Default")
= False
Output.Show(jo.ToXML)
显示的结果为:
<XML><Name>张三</Name><Group>VIP</Group><Type>2</Type><Default>false</Default></XML>
示例二
生成嵌套的XML。
在命令窗口执行:
Dim
xo As
New Foxtable.XObject
xo("name")
= "李云龙"
xo("age")
= "36"
xo("card")
= New JObject
xo("card")("bank")
= "工行"
xo("card")("account")
= "12345678"
Output.Show(xo.ToXML)
显示的结果为:
<xml><name>李云龙</name><age>36</age><card><bank>工行</bank><account>12345678</account></card></xml>
示例三
生成带数组的XML。
在命令窗口执行:
Dim
jo As
New Foxtable.XObject
jo("Name")
= "张三"
jo("Group")
= "VIP"
jo("Roles")
= New Jarray("manager","developer")
'定义数组
jo("Type")
= 2
Output.Show(jo.ToXML)
显示的结果为:
<XML><Name>张三</Name><Group>VIP</Group><Roles>manager</Roles><Roles>Developer</Roles><Type>2</Type></XML>
示例四
生成包括对象数组的XML。
在命令窗口执行:
Dim
jo As
New Foxtable.XObject
Dim
ja As
New JArray
jo("dept")
= "销售部"
jo("mpr")
= "赵刚"
jo("staff")
= ja '
For
i As
Integer = 1
To 2
Dim so
As New
JObject
If
i = 1
Then
so("name")
= "李云龙"
so("age")
= 36
Else
so("name")
= "黄晓明"
so("age")
= 26
End If
ja.Add(so)
Next
Output.Show(jo.ToXML)
显示的结果为:
<XML><dept>销售部</dept><mpr>赵刚</mpr><staff><name>李云龙</name><age>36</age></staff><staff><name>黄晓明</name><age>26</age></staff></XML>