PigsIncorporated PigsIncorporated - 3 months ago 14
C# Question

Parse DSML XML in C#

I have a DSML XML being pulled from our intranet that I need to parse to pull the values from. The start of the XML looks like below.
I'm looking at how to get started with pulling off the values such as name, email, etc. The schema and what code I have don't seem to be working. Any help would be appreciated.

<?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>

Answer
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);
}}}

Output:

dsml:attr>> ssodialcommfax dsml:value>>

1 dsml:attr>> hrindustrygroup dsml:value>> Group Name

2 dsml:attr>> ssoaceid dsml:value>> 1234567

3 dsml:attr>> ssoknownas dsml:value>> John

4 dsml:attr>> mail dsml:value>> john.doe@company.com

5 dsml:attr>> uid dsml:value>> 1234567