sign in | join about | help | sitemap
Connecting Tech Pros Worldwide
David Thielen's Avatar

Namespace problems


Question posted by: David Thielen (Guest) on November 12th, 2005 05:08 AM
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_NameTabl e());

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?

--
thanks - dave
1 Answer Posted
Pascal Schmitt's Avatar
Guest - n/a Posts
#2: Re: Namespace problems

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).

--
Pascal Schmitt
 
Not the answer you were looking for? Post your question . . .
196,827 members ready to help you find a solution.
Join Bytes.com

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 196,827 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors