PDA

Click to See Complete Forum and Search --> : Including XML Schema reference when XML file is created


alaneaston666
Aug 19th, 2005, 09:26 AM
Hello All,

I am just getting into vb.net and XML, a daunting task.

I am creating an XML file from a recordset, but need to include references to XML schemas at the very beginning of the XML file.......how do I do that.

I used the following as a test, but need to include the references to the schemas somehow.

mywriter = New System.Xml.XmlTextWriter(Server.MapPath("myfoo666.xml"), System.Text.Encoding.UTF8)
With mywriter
'NEED SOMETHING IN HERE TO REFERENCE THE SCHEMA(.XSD) FILES...?????.....
.WriteStartElement("MyBooks")
.WriteStartElement("Book")
.WriteAttributeString("ISBN", "1861005652")
.WriteAttributeString("Title", "How to make XML Work")
.WriteElementString("Author", "A. N. Other")
.WriteEndElement() 'For Book
.WriteEndElement()
End With
mywriter.Flush()
mywriter.Close()

Please, has anyone any ideas, I am struggling a bit.

Many Thanks,

Al...

shunt
Aug 23rd, 2005, 09:44 AM
You need 2 attributes as shown below:

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="schema.xsd">
<node />
<node />
<node />
</root>

alaneaston666
Aug 23rd, 2005, 09:47 AM
Thanks Shunt,

But I need to know how, or even if, you can create this dynamically at the top of the document, as I stated in my original post.

I was thinking that maybe I could call a class, give it the physical path to my XSD file, and it would write it out at the top of my XML document, before I called the first WriteStartElement command.

Any ideas.....?????