0

I'm updating the XML file with additional data which needs to be stored in the root called "PaketniUvozObrazaca" and it needs to be a new line under </Obrazac1022> child node. Here is my code so far

XDocument doc = XDocument.Load(@"C:\Test\Test.xml");
doc.Element("PaketniUvozObrazaca").Add(new XElement("Obrazac1022",
    new XElement("Dio1PodaciOPoslodavcuIPoreznomObvezniku",
    new XElement("JIBJMBPoslodavca", this.label7.Text),
    new XElement("Naziv", this.label9.Text),
    new XElement("AdresaSjedista", this.label11.Text))));
doc.Save(@"C:\Test\Test.xml");

A snippet of XML looks like

<PaketniUvozObrazaca xmlns="urn:PaketniUvozObrazaca_V1_0.xsd">
  <PodaciOPoslodavcu>
    <JIBPoslodavca>4209862630000</JIBPoslodavca>
    <NazivPoslodavca>PZU APOTEKE LA VITA</NazivPoslodavca>
    <BrojZahtjeva>11</BrojZahtjeva>
    <DatumPodnosenja>2021-12-28</DatumPodnosenja>
  </PodaciOPoslodavcu>
  <Obrazac1022>
some data
</Obrazac1022>
New line goes here
</PaketniUvozObrazaca>

And I get an error message when I execute the code as follows:

Object reference not set to an instance of an object.'

Any help would be highly appreciated.

Uwe Keim
  • 38,279
  • 56
  • 171
  • 280

0 Answers0