从字符串输入中读取xml元素 [英] read xml element from string input

查看:74
本文介绍了从字符串输入中读取xml元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是dinakar
Iam具有将xmldata作为输入数据的函数,并且我已从该xmlstring输入中提取元素值

this is dinakar
Iam having a function which has xmldata as input data and i have extract element values from that xmlstring input

string function1()
{
<car>maruthi</car>
<bike>....</bike>
.
.
.
return xml.innertext.tostring()
}
function2(string xmldata)//its input is from previous functio1 strinxml output
{
/// need code to read xml element from sting xmldata
}


请帮助我,请


please help me out please

推荐答案

实际上有很多方法可以做到.一种方法是使用GetElementsByTagName.请在下面查看我的示例

There are actually lots of ways to do it. One way is by using GetElementsByTagName. Please see my example below

XmlDocument xml = new XmlDocument();
            xml.LoadXml("<test><node1>testnode</node1></test>");
            XmlNodeList nodes = xml.GetElementsByTagName("node1");
            string value = nodes[0].InnerText;//this one returns testnode



进一步了解 System.Xml命名空间 [



Read more about System.Xml Namespace[^].


这不是紧急的.我们想帮助别人,但我们并不特别在乎您是否已接受任务,而您不知道该怎么做,或者您的截止日期是什么.

您可以使用XmlDocument类或LINQ将其解析为XML.网络上有大量信息,而且您的问题过于广泛,无法提供更具体的答案.
It''s not urgent. We like to help people, but we don''t specifically care that you''ve been given tasks you have no idea how to do, or what your deadline is.

You would parse it as XML, using the XmlDocument class, or LINQ. Tons of info on the web, and your question is too broad for a more specific answer than that.


这篇关于从字符串输入中读取xml元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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