Hi,
I am having trouble with creation of XML programmatically using .NET. Specifically Im trying to create an element which looks like below and insert into an existing xml doc:
<Worksheet ss:Name="TKCSheet1">
</Worksheet>
The existing xml doc is:
<?xml version="1.0"?>
<?mso-application progid="Excel.Sheet"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:o="urn:schemas-microsoft-com:office:office"
xmlns:x="urn:schemas-microsoft-com:office:excel"
xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
xmlns:html="http://www.w3.org/TR/REC-html40">
</Workbook>
I had no problem using LoadXml() to read this existing xml into m_XmlDoc.
But the code I am using for creating that Worksheet node (as explained above):
// add new worksheet xml node at the end of the document
XmlElement wsNode = m_XmlDoc.CreateElement("Worksheet");
XmlAttribute wsName = m_XmlDoc.CreateAttribute("ss:Name");
//XmlAttribute wsName = m_XmlDoc.CreateAttribute("ss", "Name", XmlNsMgr.LookupNamespace("ss")); //- this did not work either :(
wsName.Value = ?TKCSheet1?;
wsNode.Attributes.Append(wsName);
m_XmlDoc.DocumentElement.AppendChild(wsNode);
But this code gives me:
<Worksheet Name="TKCSheet1" xmlns="">
</Worksheet>
I want ss:Name NOT just Name, in my xml and also I do NOT want xmlns="" in that element!
Can somebody please help me out here?
Thanks,
Krishna
PS: I know probably using Excel 2003 .NET libraries might be cleaner, but I have limited to get this thing running.
--------------------------------
From: Krishna Tulasi
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>tq30o75pHke+OTwMr4tQXQ==</Id>