0

What I'm trying to do is create an XmlNode at a specific path if it doesn't exist.

My function looks like this:

public XmlElement getElement(string path) 
{
    XmlElement result = (XmlElement)document.SelectSingleNode(path);
    if (result == null) {
        // TODO: Create the specified path here
    }
    return result;
}

Is there any built-in function I can use to create the element at the specified path? The path might contain attributes like this /root/element[@id="5"]/subelement/item[@name="thing"].

Thanks in advance!

Vojtěch Dohnal
  • 7,867
  • 3
  • 43
  • 105
Qub1
  • 1,154
  • 2
  • 14
  • 31
  • Essentially you want to create nodes from the XPath query. There is a discussion of that on this [http://stackoverflow.com/questions/508390/create-xml-nodes-based-on-xpath](question). Essentially, it is isn't totally doable, but if you make some assumptions or restrictions, you can do it partway. – Grax32 Dec 16 '14 at 18:45
  • Are you trying to create the whole xml structure based off the xpath or just an attribute? – diaz994 Dec 16 '14 at 18:52
  • @diaz994 Yeah I'm trying to create the whole xml structure – Qub1 Dec 16 '14 at 19:40

0 Answers0