计算XML字符串中的记录数 [英] Counting the number of records in a XML String

查看:58
本文介绍了计算XML字符串中的记录数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我收到一个XML字符串,例如

< record>

< value> ... < / value>

< / record>

< record>

< value> ...< / value>

< / record> .......等等,

现在我想知道该XML字符串中的记录是怎么样的,我这样做

不想写任何东西到驱动器有没有办法处理那个

字符串在内存中并获取记录数?


谢谢!

Hi,

I receive an XML string like
<record>
<value>...</value>
</record>
<record>
<value>...</value>
</record>....... etc.,

Now i want to find out how may records are there in that XML string, I do
not want to write anything to the drive is there any way to process that
string in the memory and get the number of records??

Thanks!

推荐答案

hi

XmlDocument doc = new XmlDocument();

doc.LoadXML(" myXmlstring");

XmlNodeList elemList = doc.GetElementsByTagName(" record");


now elemList.Count将给出记录数


问候

Ansil


" GeRmIc"写道:
hi
XmlDocument doc = new XmlDocument();
doc.LoadXML("myXmlstring");
XmlNodeList elemList = doc.GetElementsByTagName("record");

now elemList.Count will give the number of records

regards
Ansil

"GeRmIc" wrote:


我收到一个XML字符串,如
< record>
< value> ...< ; / value>
< / record>
< record>
< value> ...< / value>
< / record> .... ......等等,现在我想知道那个XML字符串中是否有记录,我不想写任何东西到驱动器有什么方法可以处理那个
字符串在内存中并获得记录数量?

谢谢!
Hi,

I receive an XML string like
<record>
<value>...</value>
</record>
<record>
<value>...</value>
</record>....... etc.,

Now i want to find out how may records are there in that XML string, I do
not want to write anything to the drive is there any way to process that
string in the memory and get the number of records??

Thanks!



Hi Ansil,


感谢您的帮助,它适用于其他情况,但是当我的XML字符串是

时,我该怎么办? :(


< ns1:gName2 xmlns:ns1 =" http://abcd/gName2.xsd">

< ns1:ngid> ; 763777< / ns1:ngid>

< ns1:ntype> 4< / ns1:ntype>

< / ns1:germplasmName2>

< ns2:gName2 xmlns:ns1 =" http://abcd/gName2.xsd">

< ns1:ngid> 763777< / ns1:ngid>

< ns1:ntype> 4< / ns1:ntype>

< / ns2:germplasmName2>等等,


这实际上是由CASTOR编组并由Java Web服务返回。


谢谢!
Hi Ansil,

Thanks for your help, it works in other situations but when my XML string is
like this what do i do?? :(

<ns1:gName2 xmlns:ns1="http://abcd/gName2.xsd">
<ns1:ngid>763777</ns1:ngid>
<ns1:ntype>4</ns1:ntype>
</ns1:germplasmName2>
<ns2:gName2 xmlns:ns1="http://abcd/gName2.xsd">
<ns1:ngid>763777</ns1:ngid>
<ns1:ntype>4</ns1:ntype>
</ns2:germplasmName2> etc.,

This is actually marshalled by CASTOR and returned by a Java Web Service.

Thanks!


这不是格式良好的XML,是这是一个直接剪切和粘贴?


问候


Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog


nntp ://news.microsoft.com/microsoft.public.dotnet.languages.csharp/< 57 **************************** ******@微soft.co m>


您好Ansil,


感谢您的帮助,它适用于其他情况但是当我的XML字符串是

像这样我该怎么办? :(


< ns1:gName2 xmlns:ns1 =" http://abcd/gName2.xsd">

< ns1:ngid> ; 763777< / ns1:ngid>

< ns1:ntype> 4< / ns1:ntype>

< / ns1:germplasmName2>

< ns2:gName2 xmlns:ns1 =" http://abcd/gName2.xsd">

< ns1:ngid> 763777< / ns1:ngid>

< ns1:ntype> 4< / ns1:ntype>

< / ns2:germplasmName2>等等,


这实际上是由CASTOR编组并由Java Web服务返回。


谢谢!


---

收到的邮件经过认证的无病毒。

由AVG反病毒系统检查( http: //www.grisoft.com)

版本:6.0.770 /病毒库:517 - 发布日期:27/09/2004


[microsoft.public.dotnet.languages.csharp]
This isn''t well formed XML, is this a direct cut and paste?

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<57**********************************@microsoft.co m>

Hi Ansil,

Thanks for your help, it works in other situations but when my XML string is
like this what do i do?? :(

<ns1:gName2 xmlns:ns1="http://abcd/gName2.xsd">
<ns1:ngid>763777</ns1:ngid>
<ns1:ntype>4</ns1:ntype>
</ns1:germplasmName2>
<ns2:gName2 xmlns:ns1="http://abcd/gName2.xsd">
<ns1:ngid>763777</ns1:ngid>
<ns1:ntype>4</ns1:ntype>
</ns2:germplasmName2> etc.,

This is actually marshalled by CASTOR and returned by a Java Web Service.

Thanks!

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.770 / Virus Database: 517 - Release Date: 27/09/2004

[microsoft.public.dotnet.languages.csharp]


这篇关于计算XML字符串中的记录数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆