遍历一个xml并输出指定节点的值 - .NET技术 / C#
我有一个类似的xml的 string,想通过遍历怎么个xml 输出我想要的element的值
xml 为:
<Discover xmlns="urn:schemas-microsoft-com:xml-analysis">
<RequestType>DISCOVER_XML_METADATA</RequestType>
<Restrictions>
<RestrictionList>
<ObjectExpansion>ObjectProperties</ObjectExpansion>
</RestrictionList>
</Restrictions>
<Properties>
<PropertyList>
</PropertyList>
</Properties>
</Discover>
我现在通过遍历,先判断是否有 ObjectExpansion 节点,如果有输出其值。
请指教。
C# code:
// XML 读取XML文件中的元素和元素属性
private static void PrintElement(XmlDocument document)
{
XmlNodeList nodeList = document.GetElementsByTagName("*"); //获取所有的Node
for (int i = 0; i < nodeList.Count; i++)
{
XmlNode node = nodeList.Item(i);
MessageBox.Show(node.Name); //打印每一个node的名称
}
}
private static void PrintAttributes(XmlDocument document)
{
XmlNodeList nodeList = document.GetElementsByTagName("*");
XmlNamedNodeMap nameNodeMap;
XmlElement element;
XmlAttribute attribute;
string at
相关问答:
最近在做个网上商城,购物车模块,没有做过,麻烦各位帮忙说下大致说下思路,能发一份源码更好。小弟先谢过各位了;
QQ:413763818;
eamil:swebook@126.com
网上一大堆!
www.51aspx.com
去下 ......
21cn的邮箱,在outlook配置后可以正常收发邮件,可是我写在C#中就不行,换成其它邮箱,163很早注册的。可以发送。查了很久,没有找到原因,请高手帮忙解答。。。小弟,谢了。。代码如下:
private void SendMail ......
<?xml version="1.0" encoding="utf-8" ?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical&q ......
我们C#做一个窗体 往数据库里插入数据
SqlConnection cn = new SqlConnection("Data Source=20090713-1752\\SQLEXPRESS;Initial Catalog=goods;Integrated Security=True");
......
Private Sub Command1_Click()
Dim MyString() As String
Open "a.xml" For Binary As #1 ' 打开刚创建的文件。
ReDim MyString(LOF(1) - 1)
Put #1, , MyRecord ' 读入所有字符到变量中 ......