0

I've been trying for a couple hours to get this working and feeling a little embarrassed because I know it's simple. Don't have much experience working with XML data and have been trying to read up as I go.

I'm working with a class that has an XMLElement property that I'm trying to set, but I'm struggling to create the XMLElement object as I need it. This is what the XML needs to look like:

<Criteria>         
  <p1:PersonCriteria xmlns:p1="com/thomsonreuters/schemas/search"> 
    <SSN>999-99-9990</SSN>
  </p1:PersonCriteria>   
</Criteria>

I know you can't create an xmlelement without an xmldocument, so my strategy was going to be to create an xmldocument and then just pull the element out of it when I need to set this property. This is where I'm at right now:

XmlDocument criteria = new XmlDocument();
XmlElement personCriteria = criteria.CreateElement("p1", "PersonCriteria", "com/thomsonreuters/schemas/search");

What I can't figure out is how to get the SSN element nested under the personCriteria element. Any pointers here? I know there's a good chance I'm approaching this the completely wrong way, if anyone could help me out of my ignorance here it would be greatly appreciated.

  • Sorry, wrong duplicate... Should be XmlNode one, not XElement - please close as duplicate of http://stackoverflow.com/questions/14798854/c-xml-adding-new-nodes instead of http://stackoverflow.com/questions/32707644/adding-child-nodes-to-an-xelement – Alexei Levenkov Jan 31 '17 at 17:20
  • Another victim of namespaces – William Walseth Jan 31 '17 at 17:41

0 Answers0