<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:eventNotification xmlns:ns2="http://icm.alu.com/data/event" xmlns:ns1="http://icm.alu.com/data/common" xmlns:ns4="http://icm.alu.com/data/displayGroup" xmlns:ns3="http://icm.alu.com/data/call" xmlns:ns5="http://icm.alu.com/data/settings" xmlns:ns6="http://icm.alu.com/data/messaging" xmlns:ns7="http://icm.alu.com/data/adjunct">
<ns2:farEndAlertingEvent>
<ns1:forUserId ns1:userId="01535" ns1:partitionId="qat01"/>
<ns2:callID>29</ns2:callID>
<ns2:lineId>+16328301535</ns2:lineId>
<ns2:callParties ns1:userName="Unknown" ns1:phoneId="+16328311530"/>
<ns2:clientId>1000062</ns2:clientId>
</ns2:farEndAlertingEvent>
</ns2:eventNotification>
以上是xml文件
我想取出ns1:userId="01535"这一个值 我应该怎么写啊
我是菜鸟 刚刚接触xml不久 求高手帮助
<ns2:eventNotification xmlns:ns2="http://icm.alu.com/data/event" xmlns:ns1="http://icm.alu.com/data/common" xmlns:ns4="http://icm.alu.com/data/displayGroup" xmlns:ns3="http://icm.alu.com/data/call" xmlns:ns5="http://icm.alu.com/data/settings" xmlns:ns6="http://icm.alu.com/data/messaging" xmlns:ns7="http://icm.alu.com/data/adjunct">
<ns2:farEndAlertingEvent>
<ns1:forUserId ns1:userId="01535" ns1:partitionId="qat01"/>
<ns2:callID>29</ns2:callID>
<ns2:lineId>+16328301535</ns2:lineId>
<ns2:callParties ns1:userName="Unknown" ns1:phoneId="+16328311530"/>
<ns2:clientId>1000062</ns2:clientId>
</ns2:farEndAlertingEvent>
</ns2:eventNotification>
以上是xml文件
我想取出ns1:userId="01535"这一个值 我应该怎么写啊
我是菜鸟 刚刚接触xml不久 求高手帮助
XmlNodeList nodeList = XmlDoc.SelectSingleNode("data").ChildNodes;
string url = "";
foreach (XmlNode xnode in nodeList)//遍历所有子节点
{
for (int i = 0; i < xnode.Attributes.Count; i++)
{
if(xnode.Attributes[i].LocalName == nodeName)
{
url = xnode.threeNode.NamespaceURI;
return xnode.Attributes[nodeName, url].Value;//nodeName是我传入的"userId"
}
}
}
我是这样解决的
var query = from ele in rootE.Elements("forUserId")
select new ele.Attribute("userId").Value
c#:
XDocument doc = new XDocument();
var rssXDoc = XDocument.Load(@"c:\TacticMemberSelect.xml"); var classNode = rssXDoc.Descendants("class");
foreach (XElement xElement in classNode)
{
var className = xElement.Attribute("name");
var sourceType = xElement.Attribute("type");
var toString = xElement.Attribute("ToString");
var propertys = xElement.Descendants("property");
foreach (XElement property in propertys)
{
var propertyName = property.Attribute("name");
var propertyType = property.Attribute("type");
var attributes = property.Descendants("attribute");
foreach (XElement attribute in attributes)
{
var attributeName = attribute.Attribute("name");
var attributeValue = attribute.Attribute("value");
}
}
;
}xml:
<?xml version="1.0" encoding="gb2312"?>
<TacticMemberSelect>
<class name="MemberLevelSelect" type="TacticTypeEnum.Target" ToString="会员等级">
<property name="MemberLevelChoose" type="TacticMemberDetailArrayList">
<attribute name="Editor" value="typeof(ListBoxUCConverter), typeof(System.Drawing.Design.UITypeEditor"/>
<attribute name="Category" value="设置"/>
<attribute name="DisplayName" value="会员等级"/>
<attribute name="Description" value="会员等级"/>
</property>
</class>
<class name="MemberTypeSelect" type="Target" ToString="会员类型">
<property name="MemberLevelChoose" type="TacticMemberDetailArrayList">
<attribute name="Editor" value="typeof(ListBoxUCConverter), typeof(System.Drawing.Design.UITypeEditor"/>
<attribute name="Category" value="设置"/>
<attribute name="DisplayName" value="会员等级"/>
<attribute name="Description" value="会员等级"/>
</property>
</class>
</TacticMemberSelect>