title: C#, XML, adding new nodes
body: <p>I am trying to add new nodes to an existing XML file. 
  i have this file with first test elements in it:</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;Root xmlns="http://prpa.org/XMLSchema1.xsd"&gt;
    &lt;studenti&gt;
      &lt;student&gt;
        &lt;ime&gt;test&lt;/ime&gt;
        &lt;prezime&gt;test&lt;/prezime&gt;
        &lt;ocijena&gt;0&lt;/ocijena&gt;
      &lt;/student&gt;
    &lt;/studenti&gt;
    &lt;profesori&gt;
      &lt;profesor&gt;
        &lt;ime&gt;test&lt;/ime&gt;
        &lt;prezime&gt;test&lt;/prezime&gt;
      &lt;/profesor&gt;
    &lt;/profesori&gt;
  &lt;/Root&gt;
  </code></pre>
  
  <p>I used this schema to generate this XML document</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;xs:schema id="XMLSchema1"
      targetNamespace="http://prpa.org/XMLSchema1.xsd"
      elementFormDefault="qualified"
      xmlns="http://prpa.org/XMLSchema1.xsd"
      xmlns:mstns="http://prpa.org/XMLSchema1.xsd"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
             &gt;
    &lt;xs:element name='Root'&gt;
      &lt;xs:complexType&gt;
        &lt;xs:sequence&gt;
  
    &lt;xs:element name="studenti"&gt;
      &lt;xs:complexType&gt;
        &lt;xs:sequence&gt;       
     &lt;xs:element name="student"&gt;
       &lt;xs:complexType&gt;
        &lt;xs:sequence&gt;
          &lt;xs:element name="ime" type="xs:string"/&gt;
          &lt;xs:element name="prezime" type="xs:string"/&gt;
          &lt;xs:element name="ocijena" type="xs:int"/&gt;
       &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
        &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
  
    &lt;xs:element name="profesori"&gt;
      &lt;xs:complexType&gt;
        &lt;xs:sequence&gt;
    &lt;xs:element name="profesor"&gt;
        &lt;xs:complexType&gt;
          &lt;xs:sequence&gt;
           &lt;xs:element name="ime" type="xs:string"/&gt;
           &lt;xs:element name="prezime" type="xs:string"/&gt;
      &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
  &lt;/xs:element&gt;
    &lt;/xs:sequence&gt;
    &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
  
        &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
  
  &lt;/xs:schema&gt;
  </code></pre>
  
  <p>Now, I need to add new  node</p>
  
  <pre><code> &lt;profesor&gt;
        &lt;ime&gt;test2&lt;/ime&gt;
        &lt;prezime&gt;test2&lt;/prezime&gt;
      &lt;/profesor&gt;
  </code></pre>
  
  <p>I have tried this so far:</p>
  
  <pre><code>XmlDocument xmldoc = new XmlDocument();
          xmldoc.Load(Server.MapPath("data/sve.xml"));
          XmlNode root = xmldoc.SelectSingleNode("root/profesori", null);
  
              XmlNode prof = xmldoc.CreateNode(XmlNodeType.Element, "profesor", null);
  
              XmlNode ime = xmldoc.CreateNode(XmlNodeType.Element, "ime", null);
              ime.InnerText = name;
              prof.AppendChild(ime);
  
              XmlNode prezime = xmldoc.CreateNode(XmlNodeType.Element, "prezime", null);
              prezime.InnerText = surname;
              prof.AppendChild(prezime);
  
               root.AppendChild(prof);
  
              xmldoc.Save(Server.MapPath("data/sve.xml"));
  </code></pre>
  
  <p>I also tried adding namespace menager to it:</p>
  
  <pre><code>XmlNamespaceManager nsMgr = new XmlNamespaceManager(xmldoc.NameTable);
                  nsMgr.AddNamespace("ns", xmldoc.NamespaceURI);
  XmlNode root = xmldoc.SelectSingleNode("/ns:root/ns:profesori", nsMgr);
  </code></pre>
  
  <p>and still i Cant select  parent node and add new child node to it. In debug mode "root" object is null with or without namespace so in the end I off course get an null pointer exception. </p>
  
  <p>What am i doing wrong? </p>
  
  <p>P.S. Schemas, namespaces, xml file are all local and writen by me, if that makes any difference...</p>