Hi; I am creating an XmlDocument (.net 2.0) and then saving it. I need the final xml file to look as follows (SpreadsheetML schema - I have no control over it): <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:ss="schemas-microsoft-com:office:spreadsheet"> <CustomDocumentProperties xmlns="urn:schemas-microsoft-com:office:office"> <WindwardReports dt:dt="string">Version: 4.0.12</WindwardReports> </CustomDocumentProperties> <Styles> <Style ss:ID="Default" ss:Name="Normal"> <Alignment ss:WrapText="1" ss:Horizontal="Left" ss:Vertical="Bottom"/> </Style> </Styles> ... To create a namespace (this is my best guess based on the docs & googling): element.SetAttribute(prefix.length() == 0 ? "xmlns" : ("xmlns:" + prefix), url); nameMgr.AddNamespace(prefix, url); // when I create XmlDocument I also call: nameMgr = new System.Xml.XmlNamespaceManager(xmlDoc.get_NameTable()); But what I am getting is: <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:ss="schemas-microsoft-com:office:spreadsheet"> <CustomDocumentProperties xmlns="urn:schemas-microsoft-com:office:office"> <WindwardReports dt="string" xmlns="">Version: 4.0.12</WindwardReports> </CustomDocumentProperties> <Styles xmlns="urn:schemas-microsoft-com:office:spreadsheet"> <Style ID="Default" Name="Normal" xmlns=""> <Alignment WrapText="1" Horizontal="Left" Vertical="Bottom" /> </Style> </Styles> ... What am I doing wrong? --
Hello! You usually don't have to care about the xmlns-Attributes. Just use the correct methods wich allow you to specify a prefix, localName, namespace and value for an attribute. The XmlDocument will write the necessary xmlns:ss="schemas.." for you. If you want, you may also drop the prefix and have one created automatically (but it may not look nice to humans). --
Don't see what you're looking for? Try a search.
|