遍历一个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
相关问答:
在数据库中有张表,有id,name两列,id 是主键,没有设置自增属性,在程序中取出这张表放入datatable,在这个datatable中插入一条记录,当更新数据库时提示id列不能为空,请问该怎么解决?
给它一个值!!主键不能为空 ......
DataSet导出xml 批处理(循环)得怎么处理
XML文件
<A>
<B>
<C>
</C>
&nb ......
从数据库中查询一张表的数据
select 部门,姓名 from tb
如何才能生成下面的xml格式文件
<folder state="unchecked" label="全部">
<folder state="unchecked" isBra ......
我在编写一个wince5.0的程序,想实现把PDA上的一个LIST <STRING>类型的数据序列化为XML,然后在PC上的一个webservice拿到这个XML,转化为Dataset,更新PC上的数据库,我想问怎么把XML传给webservice的呢?
......