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

WriteAttributeString


Question posted by: Bill (Guest) on November 11th, 2005 10:51 PM
I'm trying to write out an XML file from VB and have it
mostly done, but I need the following header and can't
seem to get the right syntax for the WriteAttributeString
methods to get this result.

<fsaAtlasData xmlns:xsi="http://www.w3.org/2001/XMLSchema-
instance"
xsi:noNamespaceSchemaLocation="d:/fsaATLAS/XML/SASStudent.
xsd">

I tried the following but got the error shown below it.

.WriteStartElement("fsaAtlasData")
.WriteAttributeString
("xmlns", "xsi", "http://www.w3.org/2001/XMLSchema-
instance")
.WriteAttributeString
("xsi", "noNamespaceSchemaLocation", "d:/fsaATLAS/XML/SASS
tudent.xsd")


Unhandled Exception: System.ArgumentException:
The 'xmlns' attribute is bound to the reserved
namespace 'http://www.w3.org/2000/xmlns/'.
at System.Xml.XmlTextWriter.WriteStartAttribute(Strin g
prefix, String localName, String ns)
at System.Xml.XmlWriter.WriteAttributeString(String
localName, String ns, String value)
at fsaXML.fsaXML.Main(String[] args) in C:\My
Projects\fsaXML\fsaXML.vb:line 72

2 Answers Posted
Oleg Tkachenko's Avatar
Guest - n/a Posts
#2: Re: WriteAttributeString

Bill wrote:
[color=blue]
> I'm trying to write out an XML file from VB and have it
> mostly done, but I need the following header and can't
> seem to get the right syntax for the WriteAttributeString
> methods to get this result.
>
> <fsaAtlasData xmlns:xsi="http://www.w3.org/2001/XMLSchema-
> instance"
> xsi:noNamespaceSchemaLocation="d:/fsaATLAS/XML/SASStudent.
> xsd">
>
> I tried the following but got the error shown below it.
>
> .WriteStartElement("fsaAtlasData")
> .WriteAttributeString
> ("xmlns", "xsi", "http://www.w3.org/2001/XMLSchema-
> instance")[/color]
You are trying to bind "xmlns" prefix to "xsi" namespace URI, that's wrong and
after all forbidden, because "xmlns" is special reserved attribute name and
cannot be bound to any namespace URI other than "http://www.w3.org/2000/xmlns/".
[color=blue]
> .WriteAttributeString
> ("xsi", "noNamespaceSchemaLocation", "d:/fsaATLAS/XML/SASS
> tudent.xsd")[/color]

C# code:

writer.WriteAttributeString("xmlns", "xsi", null,
"http://www.w3.org/2001/XMLSchema-instance");
writer.WriteAttributeString("xsi", "noNamespaceSchemaLocation",
"http://www.w3.org/2001/XMLSchema-instance",
"d:/fsaATLAS/XML/SASStudent.xsd");

--
Oleg Tkachenko
http://www.tkachenko.com/blog
Multiconn Technologies, Israel

Bill's Avatar
Guest - n/a Posts
#3: Re: WriteAttributeString

Worked great, thanks much.
 
Not the answer you were looking for? Post your question . . .
196,837 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,837 network members.
Post your question now . . .
It's fast and it's free

Popular Articles

Top Community Contributors