xml 文件解析

yingyys 2007-04-11 11:17:07
在用bcb 的xml data binding向导 从一个xml schema文件xx.xsd,用于生成cpp文件,解析根据xx.xsd生成的xml时,遇到当xml文件的element不在同一个namespace的时候,只解析与root element相同namespace的那些element
比如xml文件如下:
<rs:SubmitObjectsRequest
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:rs="urn:oasis:names:xsd:2.1"
xmlns:rim="urn:oasis:names:rim:xsd:2.1"
xmlns="urn:oasis:names:rim:xsd:2.1"
xsi:schemaLocation="urn:oasis:names:xsd:2.1 rs.xsd">

<LeafRegistryObjectList>
<ObjectRef id="urn:uuid:7edca82f-054d-47f2-a032-9b2a5b518fff"/>
<ObjectRef id="urn:uuid:a54d6aa5-d40d-43f9-88c5-b4633d873bdd"/>
</LeafRegistryObjectList>

</rs:SubmitObjectsRequest>
SubmitObjectsRequest 与 LeafRegistryObjectList 在不同的namespace,解析时
LeafRegistryObjectList 不能正确读出,是什么原因?
...全文
2349 27 打赏 收藏 转发到动态 举报
写回复
用AI写文章
27 条回复
切换为时间正序
请发表友善的回复…
发表回复
liu528175 2011-07-20
  • 打赏
  • 举报
回复
laowang2 2007-06-06
  • 打赏
  • 举报
回复
==
yingyys 2007-04-23
  • 打赏
  • 举报
回复
结贴.

结论是,不能太相信bcb 向导生成的代码,要自己手工处理的很多.
kysoft 2007-04-15
  • 打赏
  • 举报
回复
mark
chenxidu 2007-04-14
  • 打赏
  • 举报
回复
爱莫能助
love1124jun 2007-04-14
  • 打赏
  • 举报
回复
各位大哥,我是一位刚学程序者,有好多问题,想请几位大哥帮帮我.
我想问一下:这代码有什么用啊,用来做什么呢,
谢谢各位大哥.
如有哪位大哥愿意帮我,我将万分谢谢.
给大哥我的电话:07916990403
再次谢谢.
yesry 2007-04-13
  • 打赏
  • 举报
回复
static void ReadAttributes(LGrammarTree *pGrammarTree,StringProperties &pProperties)
{
LGrammarTree *theTree;
LGrammarTree::LoopVariant begin;

wchar_t *attr_name;
wchar_t *attr_value;
int len;

begin=pGrammarTree->Children.begin();
theTree=*begin;

attr_name=theTree->Node->Value.GetText();
begin++;

//跳过 '='
begin++;

theTree=*begin;

attr_value=theTree->Node->Value.GetText();
if(attr_value[0]==L'\"')
{
len=wcslen(attr_value);
if(len>1)
{
attr_value[len-1]=0;
attr_value++;
}
}

LWideString w;
w=attr_name;
pProperties[w]=attr_value;
}
void PrintSyntaxTree(LGrammarTree *tree,LWideString &ret)
{
LGrammarTree::LoopVariant begin,end;
LGrammarTree *theTree;

end=tree->Children.end();
for(begin=tree->Children.begin();begin!=end;begin++)
{
theTree=*begin;
if(theTree->Children.size()==0)
{
ret.Append(theTree->Node->Value);
}else
{
PrintSyntaxTree(theTree,ret);
}
}
}

static void ReadTag(LGrammarTree *pGrammarTree,tagXmlTree *pXmlTree)
{
LGrammarTree *theTree;
LGrammarTree::LoopVariant begin,end;
tagXmlTree the_xml_tree;

begin=pGrammarTree->Children.begin();

//跳过 '<'
begin++;

//到了tag名字
theTree=*begin;
PrintSyntaxTree(theTree,pXmlTree->TagName);
begin++;

end=pGrammarTree->Children.end();
while(begin!=end)
{
theTree=*begin;
if(theTree->Node->Type==sxtAttributes)
{
ReadAttributes(theTree,pXmlTree->Properties);
}else
if(theTree->Node->Type==sxtTag)
{
the_xml_tree.Children.clear();
ReadTag(theTree,&the_xml_tree);
pXmlTree->Children.push_back(the_xml_tree);
}

begin++;
}
}
yesry 2007-04-13
  • 打赏
  • 举报
回复
搞好了,下面是描述
http://blog.csdn.net/yesry/archive/2007/04/13/1563034.aspx

测试源代码非常简单
LFileLoader f(0);
if(!f.LoadFile((unsigned char *)"abc.xml",true))
return;
LWideString ww;
XmlReader xmlReader;
xmlReader.Load(f.SourceCode.GetText());
GetTreeXmlText(xmlReader.XmlTree,ww);
Memo1->Text=ww.GetText();


或者直接从这里下载源代码
http://duceland.com/XmlParser.zip
ribut9225 2007-04-13
  • 打赏
  • 举报
回复
关注
yingyys 2007-04-13
  • 打赏
  • 举报
回复
先感谢各位,因为需要解析,多种内容格式的xml,所以用xml data binding向导生成的文件,这样更简单,再研究一下了.
yesry 2007-04-13
  • 打赏
  • 举报
回复
i,我的性欲分怎么就这么低啊?
Waiting4you 2007-04-13
  • 打赏
  • 举报
回复
XMLDocument对有名空间的XML情况确实有点问题, 但是有些东东用XML Binding功能又很方便, 真是鲍鱼和熊掌啊:)
flowercity 2007-04-13
  • 打赏
  • 举报
回复
mark
ccrun.com 2007-04-13
  • 打赏
  • 举报
回复
分多就是人气旺。

传说NativeXml很不错的。
SimDesign NativeXml v2.26
http://www.ccrun.com/view.asp?id=281
rainv 2007-04-12
  • 打赏
  • 举报
回复
mark一下以后看.
yesry 2007-04-12
  • 打赏
  • 举报
回复
鹰,当时问我的时候好像说根据xml生成代码呢。原来是找读取XML的类啊?我原来Duceland Desinger自带的代码生成器支持XML parser,不过现在不支持命名空间。
回去我把Duceland Desinger升级一下以便支持命名空间,然后公布reader和writer源代码。
constantine 2007-04-11
  • 打赏
  • 举报
回复
关注,xml data binding 没见过
xml只在.net里面处理过,bcb不会
看楼下的
huzhangyou 2007-04-11
  • 打赏
  • 举报
回复
我觉得你使用别的库来操作没有问题的啊
因为那些库都市平台无关的
最后你都是放到内存进行处理啊
一个道理吧
yingyys 2007-04-11
  • 打赏
  • 举报
回复
感谢楼上的各位,现在最好是能用bcb来实现问题中的<rs:SubmitObjectsRequest>与<LeafRegistryObjectList> 分属不同的namespace ,导致解析不正确,如果<LeafRegistryObjectList> 及其子结点的namespace 前缀, 改成像<rs:LeafRegistryObjectList> ,那也可以读出来
yuko520 2007-04-11
  • 打赏
  • 举报
回复
mark
加载更多回复(7)

13,825

社区成员

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

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