【急】解析XML串的问题,请大家帮忙,解决了就结贴!!!

Little2000 2007-09-18 10:46:28
我用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 >
...全文
81 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
voyan 2007-09-18
  • 打赏
  • 举报
回复
多半是没有模板文件,你先创建一个空的xml文件,然后参考下面:

AXmlF:= 'c:\Test.xml ';
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;
WuChenCan 2007-09-18
  • 打赏
  • 举报
回复
不对呀,按你这个:
<?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 >
保存后,可以读取出的呀。。
Little2000 2007-09-18
  • 打赏
  • 举报
回复
我LoadFromXML()也不行,真是郁闷,保存也不行啊,应该有好的解决方案吧,大家快来帮帮忙吧~~
WuChenCan 2007-09-18
  • 打赏
  • 举报
回复
直接赋值可能有问题,你可以考虑先将串保存成临时XML文档,再用XMLDocument读取。。
Bear_hx 2007-09-18
  • 打赏
  • 举报
回复
如果结构固定的话,可以用XML Data Bing

1,593

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧