XML Schema how to change encoding type to iso-8859-1


VB.Net 2005

I can create my XML document and schema document, but i can not work out how to change the encoding of the xml schema from the default utf-16 to iso-8859-1.

I have workewd out how to do it with my XML document, but not schema.

some code snippets are ...

Dim schema As New XmlSchema

' element data

Dim nsmgr As New XmlNamespaceManager(New NameTable())
        Dim sw As New IO.StringWriter
        schema.Write(sw, nsmgr)

has anyone get any ideas?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
Dim doc As New XmlDocument
doc.CreateXmlDeclaration("1.0", "ISO-8559-1", "yes")

yo_daz_ukAuthor Commented:

How do i assign the schema to the xml document ?
yo_daz_ukAuthor Commented:
or vice a versa?
Become a CompTIA Certified Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Bob LearnedCommented:
Ok, I need to figure out what you are doing here.

yo_daz_ukAuthor Commented:
I have an application that creates an xml document and schema dynamically, from other data read in.

say they are assigned to c:\test.xml and C:\test.xsd

Now i have created the 2 things but i want to validate them.  The validting only works when both the xml document and the schema are set to ....


Now i can not work out how to set the ISO-8559-1 encoding for the schema.  I have taken a snippet of the code below ....

Dim schema As New XmlSchema
Dim eDataRoot As New XmlSchemaElement
eDataRoot.Name = "dataroot"

.......................................... other dynamically tags assigned here ..........................

Dim nsmgr As New XmlNamespaceManager(New NameTable())
nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema")
Dim sw As New IO.StringWriter
schema.Write(sw, nsmgr)

' Write to the file XMLSchemaLocation holds a string C:\test.xsd
Dim objWriter As New System.IO.StreamWriter(XMLSchemaLocation)

this creates a schema like so ...........

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="dataroot">

Now in order to get this validation working i need to change the encoding from utf-16 to ISO-8559-1.  I know this works because when i manually enter the iso-8559-1 it validates no problem.

Does that make more sense?
Bob LearnedCommented:
Try this:

Dim objWriter As New System.IO.StreamWriter(XMLSchemaLocation, append:=False, encoding:=System.Text.Encoding.GetEncoding(1252))


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
yo_daz_ukAuthor Commented:
No that doesnt work.

It doesnt work with GetEncoding(28591) either, which is the encoding number i used for the xml document.

It shows utf-16 in the encoding any other ideas??
yo_daz_ukAuthor Commented:
For some reason it works with a stream writer ......

Dim sw As New System.IO.StreamWriter(XMLSchemaLocation, False, ystem.Text.Encoding.GetEncoding(28591))

schema.Write(sw, nsmgr)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.