Link to home
Start Free TrialLog in
Avatar of Daniel Wilson
Daniel WilsonFlag for United States of America

asked on

.net XMLWriter and attributes

I'm using the XmlWriter class in .Net 2.0.

I'm trying to write the following bit of XML (it's part of a larger thing, but this is where I'm having a problem).
<Worksheet ss:Name="Sheet1">

The code below yields the error:
System.ArgumentException: Invalid name character in 'ss:Name'. The ':' character, hexadecimal value 0x3A, cannot be included in a name.    

What do I need to do instead?

Thanks!
Private Sub XMLWorkSheetHeader(ByVal iResultNum As Int16, ByVal iRows As Int32, ByVal iColumns As Int16, ByRef W As XmlWriter)
            W.WriteStartElement("Worksheet")
            W.WriteAttributeString("ss:Name", "Sheet" & iResultNum)

Open in new window

Avatar of abel
abel
Flag of Netherlands image

You must add the proper declarations for the namespaces, otherwise this won't work.
Avatar of Daniel Wilson

ASKER

And those namespaces would be URI's?  How do I know what URI to use?
I don't know what namespace you want to use. Probably something from microsoft's worksheets XML? You should use that namespace and declare it literally the same.

Otherwise (without a namespace) namespace prefixes (the parts before the colon) are illegal.
> How do I know what URI to use?

I don't know your application and I don't know why you want to write "ss:Name". Apparently that comes from somewhere else. Lookup that document and use the declaration from that document.
In the header of the document I see stuff like
urn:schemas-microsoft-com:office:spreadsheet
used.

Is that the kind of thing I should be using?
>>I don't know your application

I'm creating an XML spreadsheet from a data set and I want Excel to load it by default.

That's why I'm stuck on some funny-looking names -- I'm mimicking Excel's output.

Thanks for your help w/ this!
ASKER CERTIFIED SOLUTION
Avatar of abel
abel
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Past that error & on to the next ... Thanks!
Good luck with the next then :)

You're welcome & thanks for the points!