我从内部网中提取了一个DSML XML,我需要解析它以从中提取值。 XML的开头如下所示。 我正在研究如何开始提取名称,电子邮件等价值。架构和我所用的代码似乎无法正常工作。任何帮助将不胜感激。
<?xml version="1.0" encoding="UTF-8" ?>
- <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:dsml="http://www.dsml.org/DSML">
- <SOAP-ENV:Body>
- <dsml:dsml xmlns:dsml="http://www.dsml.org/DSML">
- <dsml:directory-entries>
- <dsml:entry dn="ssouid=8dc00fd1-ca9a-1642-c7f6-0003ba128a2e,ou=Worker, o=website.com">
- <dsml:objectclass>
<dsml:oc-value>top</dsml:oc-value>
<dsml:oc-value>person</dsml:oc-value>
<dsml:oc-value>organizationalPerson</dsml:oc-value>
<dsml:oc-value>inetOrgPerson</dsml:oc-value>
<dsml:oc-value>SSOperson</dsml:oc-value>
<dsml:oc-value>idmcolab</dsml:oc-value>
</dsml:objectclass>
- <dsml:attr name="ssodialcommfax">
<dsml:value />
</dsml:attr>
- <dsml:attr name="hrindustrygroup">
<dsml:value>Group Name</dsml:value>
</dsml:attr>
- <dsml:attr name="ssoaceid">
<dsml:value>1234567</dsml:value>
</dsml:attr>
- <dsml:attr name="ssoknownas">
<dsml:value>John</dsml:value>
</dsml:attr>
- <dsml:attr name="mail">
<dsml:value>john.doe@company.com</dsml:value>
</dsml:attr>
- <dsml:attr name="uid">
<dsml:value>1234567</dsml:value>
</dsml:attr>
</dsml:entry>
</dsml:directory-entries>
</dsml:dsml>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
答案 0 :(得分:0)
如果您没有将xml复制并粘贴到此问题上,则xml格式不正确请在最后添加以下行,然后再尝试解析;
...
</dsml:entry>
</dsml:directory-entries>
</dsml:dsml>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
答案 1 :(得分:0)
using System;
using System.Xml;
namespace parseXML
{
class Program
{
public static void Main(string[] args)
{
XmlDocument doc = new XmlDocument();
doc.Load("parse.xml");
XmlNode child;
int count=doc.GetElementsByTagName("dsml:attr").Count;
for(int i=0;i<=count-1;i++)
{
child=doc.GetElementsByTagName("dsml:attr")[i];
Console.WriteLine(i);
Console.WriteLine("dsml:attr>> "+child.Attributes["name"].Value);
Console.WriteLine("dsml:value>> "+child.ChildNodes[0].InnerText);
}
Console.ReadKey(true);
}}}
输出:
DSML:ATTR&GT;&GT; ssodialcommfax DSML:值GT;&GT;
1 DSML:ATTR&GT;&GT; hrindustrygroup DSML:值GT;&GT;集团名称
2 DSML:ATTR&GT;&GT; ssoaceid DSML:值GT;&GT; 1234567
3 DSML:ATTR&GT;&GT; ssoknownas DSML:值GT;&GT;约翰
4 DSML:ATTR&GT;&GT;邮件 DSML:值GT;&GT; john.doe@company.com
5 DSML:ATTR&GT;&GT; UID DSML:值GT;&GT; 1234567
答案 2 :(得分:0)
尝试以下xml linq
MATCH (b:Bill{Year:"2016"})-[r:COAUTHORED_BY|COSPONSORED_BY|SPONSORED_BY]-(c:Legislators)
WHERE b.name CONTAINS "HB" OR b.name CONTAINS "SB"
RETURN b.name, b.Short_description, COUNT(r) AS TOTAL, COUNT(c.Party = "Republican"), COUNT(c.Party = "Democratic")
ORDER BY COUNT(r) desc