Heya,
I'm trying to write (create a node) to an existing xml file wich has a namespace.
The following code gives "Object reference not set ....":
The file:
I suppose I need to use the NameSpaceManager for this, but how to write to it so it looks like this:
Thanks for the help in advance.
I'm trying to write (create a node) to an existing xml file wich has a namespace.
The following code gives "Object reference not set ....":
Code:
Dim xdoc As New XmlDocument ' write the values to the .rels.xml
xdoc.Load("myfile.xml")
xdoc.DocumentElement("Relationships").InnerText = "Relationship Id="test"....etc" <--- Object reference not set
xdoc.saveCode:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId3" Type="...." Target="docProps/app.xml"/>
<Relationship Id="rId2" Type="..." Target="docProps/core.xml"/>
<Relationship Id="rId1" Type="..." Target="xl/workbook.xml"/>
</Relationships>Code:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="test"> ' <---- my node/string to add
<Relationship Id="rId3" Type="...." Target="docProps/app.xml"/>
<Relationship Id="rId2" Type="..." Target="docProps/core.xml"/>
<Relationship Id="rId1" Type="..." Target="xl/workbook.xml"/>
</Relationships>Code:
Dim xdoc As New XmlDocument
xdoc.Load(myxml)
Dim mynsman As New XmlNamespaceManager(xdoc.NameTable)
mynsman.AddNamespace("Relationships", "http://schemas.openxmlformats.org/package/2006/relationships")
' now I don't know what to do next....