Click to See Complete Forum and Search --> : .Net doesn't accept xmlns="something non-standard"


BKT
November 29th, 2002, 09:50 AM
I programmatically generate an XML file for transferring information to another web site
and I use a non-standard XML Namespace in my DocumentElement and this seems to be a problem
for VS.Net.

The first problem is that when I generate my DocumentElement using XMLDocument.CreateElement
it butchers the XML created because I use something other than xmlns="http://www.w3.org" or
whatever. In particular my xmlns:xsi and xsi:schemaLocation attributes are mangled.
I got round this by the rather dirty trick of hard coding the XML into a string and then doing a
XMLDocument.InnerXML = String

My suspicion is that VS.Net is broken but it may also be that there is some clever line of
code or option which I need to set which will make all the difference.

My first question is does anybody know how to make .Net accept non-standard xml namespaces?

Secondly, I then go on to programmatically generate other XML elements and whenever I do
a CreateEelement and AppendChild to my DocumentElement .Net creates a spurious xmlns=""
attribute. Again, I can fix this in a quick and dirty way at the end of my processing by
extracting the InnerXML and replacing this rubbish with empty string, but I'd like to do
something cleaner.

It seems clear to me that these two problems are related and fixing one will fix the other.

Any ideas anybody?

FWIW here is a cut-down version of what I want to generate -

<?xml version="1" encoding="UTF-8" ?>
<OTA_xxx xmlns="http://www.opentravel.org/OTA"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opentravel.org/OTA OTA_xxx"
AnotherAttr="SomeValue"
>
<AnotherElt attr2="Value" />
</ OTA_xxx>

Additional information -
There is nothing wrong with the XML I want to generate according to XMLSpy.
I've downloaded a whole of xsd files from http://www.opentravel.org/OTA and used
XMLSpy to validate my XML file with the xsi:schemaLocation attribute pointing to
http://www.opentravel.org/OTA 'downloaded xsd files on my hard disk'