谁能帮我用c++bulider6.0解析以下xml文件

junweili 2012-04-25 05:41:47




<?xml version="1.0" encoding="utf-8"?><!--Current Version:V01R10--><GetAuto-distributeMAC><Export><ResultData><LineRow><guid_type_id>0</guid_type_id><guid_type_name>MAC</guid_type_name><mac_code>781DBA32F56F-78(9)</mac_code><code>5</code><print_copies></print_copies><tip>2102310BJS6TBBTEST01</tip></LineRow><LineRow><guid_type_id>3</guid_type_id><guid_type_name>SN</guid_type_name><mac_code>4857544332F56F04</mac_code><code>1</code><print_copies></print_copies><tip>2102310BJS6TBBTEST01</tip></LineRow><LineRow><guid_type_id>8</guid_type_id><guid_type_name>E8C</guid_type_name><mac_code>HG8245,08-19-A6-22-4F-9B,ChinaNet-PPG6,6tzjparv,192.168.1.1,useradmin,kaqrj,12VDC,2A,0819A6-4D3000819A6224F9B</mac_code><code>1</code><print_copies></print_copies><tip>2102310BJS6TBBTEST01</tip></LineRow></ResultData><Message><ErrorCode>0</ErrorCode><ErrorMsg>Sucess</ErrorMsg></Message></Export></GetAuto-distributeMAC>
...全文
117 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Jim@luckeeinc.com 2012-04-27
  • 打赏
  • 举报
回复
根据你的xml修改一下程序不就可以了?
TList * TForm1:: Get_Info_From_Xml(String xml)
{
_di_IXMLDocument XMLDoc;
XMLDoc = NewXMLDocument();
try
{
//XMLDoc->LoadFromFile((WideString)file);
XMLDoc->LoadFromXML((WideString)xml);
XMLDoc->Active=true;
}
catch(...)
{
return NULL;
}

_di_IXMLNode node=XMLDoc->DocumentElement;
TList *list = new TList();

_di_IXMLNodeList first_nodes = node->ChildNodes->Nodes[0]->ChildNodes;
for(int k = 0; k < first_nodes->Count; k++)
{
String str = first_nodes->Nodes[k]->NodeName;
if(str == "ResultData")
{
_di_IXMLNodeList nodes = first_nodes->Nodes[k]->ChildNodes;
for(int n=0;n<nodes->Count;n++)
{
TStringList *sg = new TStringList;
for(int j = 0; j < nodes->Nodes[n]->ChildNodes->Count; j++) //硂琌ノㄓ弄nodefield
{
String str_name = nodes->Nodes[n]->ChildNodes->Nodes[j]->NodeName;
String str_value = "";
try
{
str_value = nodes->Nodes[n]->ChildNodes->Nodes[j]->NodeValue;
}
catch(...)
{
str_value = "";
}
sg->Add(str_name + "=" + str_value);
}
list->Add(sg);
}
}
else if(str == "Message")
{
_di_IXMLNodeList nodes = first_nodes->Nodes[k]->ChildNodes;
TStringList *sg = new TStringList;
for(int n=0;n<nodes->Count;n++)
{
String str_name = nodes->Nodes[n]->NodeName;
String str_value = "";
try
{
str_value = nodes->Nodes[n]->NodeValue;
}
catch(...)
{
str_value = "";
}
sg->Add(str_name + "=" + str_value);
}
list->Add(sg);
}
}
return list;
}
void __fastcall TForm1::Button1Click(TObject *Sender)
{
String str = "<?xml version=\"1.0\" encoding=\"utf-8\"?><!--Current Version:V01R10--><GetAuto-distributeMAC><Export><ResultData><LineRow><guid_type_id>0</guid_type_id><guid_type_name>MAC</guid_type_name><mac_code>781DBA32F56F-78(9)</mac_code><code>5</code><print_copies></print_copies>";
str += "<tip>2102310BJS6TBBTEST01</tip></LineRow><LineRow><guid_type_id>3</guid_type_id><guid_type_name>SN</guid_type_name><mac_code>4857544332F56F04</mac_code><code>1</code><print_copies></print_copies><tip>2102310BJS6TBBTEST01</tip></LineRow><LineRow><guid_type_id>8</guid_type_id><guid_type_name>E8C</guid_type_name><mac_code>HG8245,08-19-A6-22-4F-9B,ChinaNet-PPG6,6tzjparv,192.168.1.1,useradmin,kaqrj,12VDC,2A,0819A6-4D3000819A6224F9B</mac_code><code>1</code><print_copies></print_copies><tip>2102310BJS6TBBTEST01</tip></LineRow></ResultData><Message><ErrorCode>0</ErrorCode><ErrorMsg>Sucess</ErrorMsg></Message></Export></GetAuto-distributeMAC>";
TList *list = Get_Info_From_Xml(str);
for(int i = 0; i < list->Count; i++)
{
ShowMessage(((TStringList *)(list->Items[i]))->Text);
}
}
junweili 2012-04-27
  • 打赏
  • 举报
回复
还是没能解析出所有节点的内容,哪位大侠帮帮我啊!时间很紧迫
Jim@luckeeinc.com 2012-04-26
  • 打赏
  • 举报
回复
bcb可以直接解析的
#include <XMLDoc.hpp>

以下是示例函数,有多层的话自己处理一下
TList *Get_Info_From_Xml(String xml)
{
_di_IXMLDocument XMLDoc;
XMLDoc = NewXMLDocument();
try
{
//XMLDoc->LoadFromFile((WideString)file);
XMLDoc->LoadFromXML((WideString)xml);
XMLDoc->Active=true;
}
catch(...)
{
return NULL;
}

_di_IXMLNode node=XMLDoc->DocumentElement;
_di_IXMLNodeList nodes=node->ChildNodes;

TList *list = new TList();
for(int n=0;n<nodes->Count;n++)
{
TStringList *sg = new TStringList;
for(int j = 0; j < nodes->Nodes[n]->ChildNodes->Count; j++) //硂琌ノㄓ弄nodefield
{
String str_name = nodes->Nodes[n]->ChildNodes->Nodes[j]->NodeName;
String str_value = "";
try
{
str_value = nodes->Nodes[n]->ChildNodes->Nodes[j]->NodeValue;
}
catch(...)
{
str_value = "";
}
sg->Add(str_name + "=" + str_value);
}
list->Add(sg);
}
return list;
}
缘中人 2012-04-26
  • 打赏
  • 举报
回复
使用方法
http://topic.csdn.net/u/20111124/16/bf11b73d-0db4-4565-be44-7d67043c06aa.html
安装方法,http://topic.csdn.net/u/20110605/20/30119fbc-7a02-4869-922a-7a40e2e89593.html

缘中人 2012-04-25
  • 打赏
  • 举报
回复
nativexml类

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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