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

Little2000 2007-09-18 09:14:01
我用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>
...全文
69 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
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;

Harryfin 2007-09-18
  • 打赏
  • 举报
回复
UTF-8改成gb2312试试?
voyan 2007-09-18
  • 打赏
  • 举报
回复
为什么保存不行呢?出什么错误?
Little2000 2007-09-18
  • 打赏
  • 举报
回复
保存也不行啊,真是快疯了,感觉应该有可以解决的方案,继续等待。。。。。。
WuChenCan 2007-09-18
  • 打赏
  • 举报
回复
直接赋值可能有问题,你可以考虑先将串保存成临时XML文档,再用XMLDocument读取。。
voyan 2007-09-18
  • 打赏
  • 举报
回复
首先把收到的字符串保存成xml文件,再循环读取这个文件中的节点。

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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