我用XMLDocument来解析XML文件没有问题,文件的基本格式是这样的:
<?xml version="1.0" encoding="UTF-8"? >
<OETest name="36" type="22" >
<option content="parent1" >
<item id="55" text="测试1" > </item >
<item id="56" text="测试2" > </item >
</option >
<option content="parent1" >
<item id="4" text="考试" > </item >
</option >
</OETest >
但是,现在我收到的是XML字符串,就是把上面的内容拼成串,这样的话我把XMLDocument.XML.Text赋值成这个串就解析不出来了,找不到结点了好像,请教各位这是怎么回事?或者有其他方法可以解决这个问题吗?着急啊,解决了就结贴!!!谢谢~~
串是这样的: <?xml version="1.0" encoding="UTF-8"? > <OETest name="36" type="22" > <option content="parent1" > <item id="55" text="测试1" > </item > <item id="56" text="测试2" > </item > </option > <option content="parent1" > <item id="4" text="考试" > </item > </option > </OETest >
<?xml version="1.0" encoding="UTF-8"? >
<OETest name="36" type="22" >
<option content="parent1" >
<item id="55" text="测试1" > </item >
<item id="56" text="测试2" > </item >
</option >
<option content="parent1" >
<item id="4" text="考试" > </item >
</option >
</OETest >
但是,现在我收到的是XML字符串,就是把上面的内容拼成串,这样的话我把XMLDocument.XML.Text赋值成这个串就解析不出来了,找不到结点了好像,请教各位这是怎么回事?或者有其他方法可以解决这个问题吗?着急啊,解决了就结贴!!!谢谢~~
串是这样的: <?xml version="1.0" encoding="UTF-8"? > <OETest name="36" type="22" > <option content="parent1" > <item id="55" text="测试1" > </item > <item id="56" text="测试2" > </item > </option > <option content="parent1" > <item id="4" text="考试" > </item > </option > </OETest >
<?xml version="1.0" encoding="UTF-8"? >
<OETest name="36" type="22" >
<option content="parent1" >
<item id="55" text="测试1" > </item >
<item id="56" text="测试2" > </item >
</option >
<option content="parent1" >
<item id="4" text="考试" > </item >
</option >
</OETest >
保存后,可以读取出的呀。。
if FileExists(AXmlF) then
begin
try
list:= TStringList.Create;
list.Append( ' <?xml version="1.0" encoding="GB2312"? > ');
list.Append( ' <OETest name="36" type="22" > ');
list.Append( ' <option content="parent1" > ');
list.Append( ' <desc > ');
//list.Append( ' <archivesID > '+ID+ ' </archivesID > ');
//list.Append( ' <archivesDesc > '+Name+ ' </archivesDesc > ');
//list.Append( ' <archFlag >1 </archFlag > ');
list.Append( ' </desc > ');
list.Append( ' </archives > ');
list.Append( ' </cgrsArchives > ');
list.SaveToFile(AXmlF); //Savepath+ '\CGAMS_FILE_ '+Name+ '.xml '
finally
list.Free;
end;
end
else
begin
showmessage( '指定文件 '+AXmlF+ '不存在! ');
exit;
end;