如何使用c#找到单个xml节点值。 [英] How can find the single xml node value using c#.
本文介绍了如何使用c#找到单个xml节点值。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在不循环播放的情况下从休闲的xml中找到LastModefied值。
< BucketItem xmlns = http: //schemas.datacontract.org/2004/07/Schakra.OneAWS.S3.Core.Resources.File\" xmlns:i = http://www.w3.org/2001/XMLSchema-instance >
< ContentType > binary / octet-stream < / ContentType >
< ETag > etag < / ETag >
< LastModified > 星期二,08四月2014 11:50 :53 GMT < / LastModified >
< 元数据 xmlns:a = http://schemas.microsoft .com / 2003/10 /序列化/数组 >
< a:KeyValueOfstringstring >
< a:键 > hello < / a:Key >
< a:值 < span class =code-keyword>> 1 < / a:值 >
< / a:KeyValueOfstringstring >
< a:KeyValueOfstringstring >
< a:键 > hi < / a:密钥 >
< a:值 > 4 < / a:值 >
< / a:KeyValueOfstringstring >
< /元数据 >
< 所有者 xmlns:a = http://schemas.datacontract.org/ 2004/07 / Schakra.OneAWS.S3.Core.Resources >
< a:_x003C_DisplayName_x003E_k__BackingField > owner1 < span class =code-keyword>< / a:_x003C_DisplayName_x003E_k__BackingField >
< a:_x003C_ID_x003E_k__BackingField > 12345 < / a:_x003C_ID_x003E_k__BackingField >
< / Owner > ;
< 大小 > 444 < / Size >
< / BucketItem >
thanks
purna
解决方案
使用 XmlDocument
类 [ ^ ]。
如果我们使用它,我们不希望循环xml节点。
XmlDocument xmldocinner = new XmlDocument();
xmldocinner.Load(MetaDataRepository +/+ metadataMappedKey);
< pre < span class =code-attribute> lang = cs > var root = xmldocinner.GetElementsByTagName(& quot; LastModified& quot;);
var lastmodifieddate = root [0] .InnerText; < / pre > 跨度>
Hi,
How can I find the "LastModefied" value from the fallowing xml with out looping.
<BucketItem xmlns="http://schemas.datacontract.org/2004/07/Schakra.OneAWS.S3.Core.Resources.File" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<ContentType>binary/octet-stream</ContentType>
<ETag>etag</ETag>
<LastModified>Tue, 08 Apr 2014 11:50:53 GMT</LastModified>
<Metadata xmlns:a="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
<a:KeyValueOfstringstring>
<a:Key>hello</a:Key>
<a:Value>1</a:Value>
</a:KeyValueOfstringstring>
<a:KeyValueOfstringstring>
<a:Key>hi</a:Key>
<a:Value>4</a:Value>
</a:KeyValueOfstringstring>
</Metadata>
<Owner xmlns:a="http://schemas.datacontract.org/2004/07/Schakra.OneAWS.S3.Core.Resources">
<a:_x003C_DisplayName_x003E_k__BackingField>owner1</a:_x003C_DisplayName_x003E_k__BackingField>
<a:_x003C_ID_x003E_k__BackingField>12345</a:_x003C_ID_x003E_k__BackingField>
</Owner>
<Size>444</Size>
</BucketItem>
thanks
purna
解决方案
Use the XmlDocument
Class[^].
If we are using this we don't want loop the xml nodes.
XmlDocument xmldocinner = new XmlDocument(); xmldocinner.Load(MetaDataRepository + "/" + metadataMappedKey); <pre lang="cs">var root = xmldocinner.GetElementsByTagName("LastModified"); var lastmodifieddate = root[0].InnerText;</pre>
这篇关于如何使用c#找到单个xml节点值。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文