Click here to Skip to main content
15,917,795 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an unzipped xlsx document that consists of two xml documents, sheet1.xml and SharedStrings.xml.

Both have a xmlNameSpaceManager :
Dim workSheetManager As New XmlNamespaceManager(workSheet.NameTable)
            workSheetManager.AddNamespace("foo", "http://schemas.openxmlformats.org/spreadsheetml/2006/main")
            workSheetManager.AddNamespace("r", "http://schemas.openxmlformats.org/officeDocument/2006/relationships")


Dim sharedStringManager As New XmlNamespaceManager(sharedStrings.NameTable)
            sharedStringManager.AddNamespace("foo", "http://schemas.openxmlformats.org/spreadsheetml/2006/main")


Now the xml will only hold reference to cell that have a value, empty cells are not included, and I want to add values into a new column.

That means I have to add a child node to the sharedStrings.xml and the getting the numeric value of the node and use that to create a new node into sheet1.xml.

How do I add an new xml child node that uses the xml schemas ?

What I have tried:

I have tried appending a new child node, but this just gives me an empty node and does not make use of the schema.
Posted
Comments
Member 15627495 10-Mar-23 7:45am    
by LINQ for XML :

you create your new node :
dim elm as xelement = new xelement( name , value )

and you add it through a linq query at the good location
// LINQ query :
(from u in XML_tree...innerDepth....last() ).add(elm)

// the step after you save your new XML tree
Michel van der Laan 2023 11-Mar-23 7:37am    
The example I have given is the manual manipulation of an excel file, there are more methods available to make this work, but I want to know how it works with the namespacemanager so I can use it for any xml document that uses namespaces, not just MS Office.
Member 15627495 12-Mar-23 10:19am    
about NameSpaceManager : https://learn.microsoft.com/en-us/dotnet/standard/data/xml/managing-namespaces-in-an-xml-document

there is 'xsd' too,

the difference between NameSpaceManager and xsd comes when you have 'n > 1' xsd by your Xml content.

'Xsd' is 'a map' to build your 'Xml content' ( it's constraint Applying, validation, error fixing too )
'NameSpaceManagement' can get several 'Xsd' to apply on a Xml Content.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900