local xmlCutil = CTNXMLUtil();

-- 设置XML声明
xmlCutil:setDeclaration('这是xml的声明');

-- 判断是否已经打开
if xmlCutil:isOpen() == false then
    print('没有打开xml');
end

local sFilePath = 'E:/test_class/test_xml.xml'
-- test_xml.xml文件内容
--[[ <students>
     <class a_name = "1606D">
        <student>
             <name>俄罗斯</name>
             <age>18</age>
             <sex></sex>
         </student>
         <student>
             <name>张三</name>
             <age>20</age>
             <sex></sex>
         </student>
         <student>
             <name>李四</name>
             <age>33</age>
             <sex>不知道</sex>
         </student>
     </class>
 </students>
]]


-- 从文件中加载
if xmlCutil:load(sFilePath) == false then
    print('从文件加载失败');
else
    print('从文件加载成功');
end


-- 清空
xmlCutil:clean();
--[[
local sXmlSstr = '''
    <students>
        <class a_name = "1606D">
            <student>
                <name b_name = "1">赵四</name>
                <age>30</age>
                <sex></sex>
            </student>
            <student>
                <name b_name = "2">张三</name>
                <age>20</age>
                <sex></sex>
            </student>
            <student>
                <name b_name = "3">李四</name>
                <age>33</age>
                <sex></sex>
            </student>
        </class>
    </students>
]]
-- 从字符串加载
if xmlCutil:fromString(sXmlSstr) == false then
    print('从字符串加载失败');
else
    print('从字符串加载成功');
end
Copyright © TouchNet 2015 all right reserved,powered by Gitbook最后修订时间: 2022-06-21 09:21:04

results matching ""

    No results matching ""