[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1023
  • Last Modified:

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

All,

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?
0
yo_daz_uk
Asked:
yo_daz_uk
  • 5
  • 3
1 Solution
 
Bob LearnedCommented:
Dim doc As New XmlDocument
doc.CreateXmlDeclaration("1.0", "ISO-8559-1", "yes")

Bob
0
 
yo_daz_ukAuthor Commented:
Thanks,

How do i assign the schema to the xml document ?
0
 
yo_daz_ukAuthor Commented:
or vice a versa?
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Bob
0
 
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 ....

ISO-8559-1

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"
schema.Items.Add(eDataRoot)

.......................................... 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)
objWriter.Write(sw.ToString)
objWriter.Close()

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">
  </xs:element>
</xs:schema>

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?
0
 
Bob LearnedCommented:
Try this:

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

Bob
0
 
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??
0
 
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)
sw.Close()
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 5
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now