Avatar of Daniel Wilson
Daniel Wilson
Flag 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

.NET ProgrammingVisual Basic.NETXML

Avatar of undefined
Last Comment
abel

8/22/2022 - Mon
abel

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

ASKER
And those namespaces would be URI's?  How do I know what URI to use?
abel

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.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
abel

> 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.
Daniel Wilson

ASKER
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?
Daniel Wilson

ASKER
>>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!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
ASKER CERTIFIED SOLUTION
abel

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Daniel Wilson

ASKER
Past that error & on to the next ... Thanks!
abel

Good luck with the next then :)

You're welcome & thanks for the points!