Sorry, that should have been:
dim attr As XmlAttribute = doc.CreateAttribute("ss", "Type", "urn:schemas-microsoft-com
Copy/paste error...
Main Topics
Browse All TopicsUsing an instance of the XmlDataDocument class, am trying to create an element that looks like this <Cell ss:Type="Boolean">
Here are my namespaces:
<Workbook xmlns="urn:schemas-microso
xmlns:o="urn:schemas-micro
xmlns:x="urn:schemas-micro
xmlns:ss="urn:schemas-micr
xmlns:html="http://www.w3.
And here is my code:
'XmlDataDocument loaded successfully here...
Dim cell As XmlNode = doc.CreateElement("Cell")
dim attr As XmlAttribute = doc.CreateAttribute("ss", "Type", Nothing)
attr.Value = "Boolean"
cell.Attributes.Append(att
The result I am getting is <Cell Type="Boolean">
I have tried a number of different combinations for the CreateElement / CreateAttribute functions, but cannot seem to get the "ss" prefix to precede the attribute name. I am new to the DataDocument class, and am used to the straightforward XmlTextWriter in which the code would be WriteAttributeString("ss",
Can anyone help me out?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Okay - as a test, I put 1 textbox on a form and put this in the Page_Load event:
' Create the XML Document
Dim doc As New XmlDataDocument
' Create a root node in the ss namespace
Dim nRoot = doc.CreateNode(XmlNodeType
doc.AppendChild(nRoot)
' Create a cell element
Dim cell As XmlNode = doc.CreateElement("Cell")
' Create the Type attribute in the same namespace (Notice that the namespace URI IS specified, but doesn't get re-printed below)
Dim attr As XmlAttribute = doc.CreateAttribute("ss", "Type", "urn:schemas-microsoft-com
attr.Value = "Boolean"
' Add the attribute to the cell and the cell to the root node.
cell.Attributes.Append(att
nRoot.AppendChild(cell)
' Output the XML
TextBox1.Text = doc.OuterXml
The XML that showed up in the TextBox is:
<ss:Root xmlns:ss="urn:schemas-micr
<Cell ss:Type="Boolean" />
</ss:Root>
Hope this helps.
Thank you for your comments. However, what I am looking for is a way to also eliminate the xmlns attribute from the element. I've hacked around it by writing the DataDocument to a StringWriter, deleting the xmlns tag in the StringWriter, and then writing the contents of the StringWriter to file. However, this is definitely a sloppy way to go about it, so if anyone know of a better way to eliminate the attribute, let me know.
Just out of curiousity, why do you need to remove the attribute? The reason I ask is that xml is not considered to be "well formed" if it uses the attribute ss:Type="..." without the xmlns:ss="uri" attribute on the cell tag directly, or on a parent element.
This seems to be important because I think that it means that the build int XMLDocument (or XMLDataDocument) classes won't let you do it. As a result, I think the only solution that you're going to find is going to be to do what you've suggested above using a StreamWriter (or some similar "procedure").
One way to see this is that if you write that xml out (without the xmlns tag), and then try to load that XML back into the XMLDocument with the LoadXML function (for example), I think you'll find that you get an error.
Let me know if I'm overlooking or misunderstand something though. Good luck.
Okay, I've played around it it some more, and if the xmlns attribute is part of the workbook tag (as it seems like it is), then the xmlns attribute is not necessary in the cell. The code below is a slight modification from the original code that I posted and it specifically set's up a workbook with the namespace attributes as you have them at the beginning of your question, and then the cell tag, exactly as you want that. Hopefully this is more along the lines of what you are looking for. Good luck.
' Create document
Dim doc As New XmlDataDocument
' Create root nodes
Dim nRoot As XmlNode = doc.CreateElement("Workboo
doc.AppendChild(nRoot)
' Add all xmlns namespaces (as described in your original question)
Dim a As XmlAttribute
' Add xmlns:o
a = doc.CreateAttribute("xmlns
a.InnerText = "urn:schemas-microsoft-com
nRoot.Attributes.Append(a)
' Add xmlns:ss
a = doc.CreateAttribute("xmlns
a.InnerText = "urn:schemas-microsoft-com
nRoot.Attributes.Append(a)
'etc...
' Create the cell and add the necessary attributes
Dim cell As XmlNode = doc.CreateElement("cell")
a = doc.CreateAttribute("ss", "Type", "urn:schemas-microsoft-com
a.Value = "Boolean"
cell.Attributes.Append(a)
nRoot.AppendChild(cell)
' Show the XML
TextBox2.Text = doc.OuterXml
THIS ALL OUTPUTS THE FOLLOWING XML:
<Workbook xmlns:o="urn:schemas-micro
xmlns:ss="urn:schemas-micr
<cell ss:Type="Boolean" />
</Workbook>
Notice that the cell tag is exactly as you have requested in your original question. Will this work or am I still missing what you're trying to do?
Business Accounts
Answer for Membership
by: kalliopiPosted on 2005-09-10 at 13:00:13ID: 14857150
This gives you what you want, but it includes the namespace declaration (xmlIns) as well, which you may not want.
osoft-com: office:spr eadsheet" />
dim attr As XmlAttribute = doc.CreateAttribute("ss", "Type", Nothing)
This will output
<cell ss:Type="Boolean" xmlns:ss="urn:schemas-micr
There may be some way to suppress the xmlIns:ss attribute, but I haven't found that yet...