473,387 Members | 1,664 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

how to generate xml schema with UTF-8 instead of UTF-16

Hi,

I am writing code with C# to generate xml schema, however, the
following code generate a UTF-16 in the first line. This will create
some problems. How can get the code/missing what part of the code in C#
to generate a first line with UTF-8 instead of UTF-16? Thanks,

public XmlSchema CreateSchemaRoot()
{
schema.ElementFormDefault = XmlSchemaForm.None;
schema.AttributeFormDefault = XmlSchemaForm.Unqualified;
schema.Version = "1.0";
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("xsd", schemaNS);
schema.Namespaces = ns;
return schema;
}

Nov 12 '05 #1
1 4151


co********@yahoo.com wrote:

I am writing code with C# to generate xml schema, however, the
following code generate a UTF-16 in the first line. public XmlSchema CreateSchemaRoot()
{
schema.ElementFormDefault = XmlSchemaForm.None;
schema.AttributeFormDefault = XmlSchemaForm.Unqualified;
schema.Version = "1.0";
XmlSerializerNamespaces ns = new XmlSerializerNamespaces();
ns.Add("xsd", schemaNS);
schema.Namespaces = ns;
return schema;
}


I don't see any statement in that code snippet that serializes the schema.
The following is a complete code snippet creating an example schema and
serializing it using a StreamWriter which by default uses UTF-8 to
encoded data:

XmlSchema exampleSchema = new XmlSchema();

XmlSchemaElement elementGod = new XmlSchemaElement();
elementGod.Name = "God";
elementGod.SchemaTypeName = new XmlQualifiedName("string",
XmlSchema.Namespace);

exampleSchema.Items.Add(elementGod);

exampleSchema.Compile(new ValidationEventHandler(ValidationHandler));

XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new
NameTable());
namespaceManager.AddNamespace("xs", XmlSchema.Namespace);

using (StreamWriter schemaWriter = new
StreamWriter(@"test2005102601Xsd.xml")) {
exampleSchema.Write(schemaWriter, namespaceManager);
}

so that the resulting schema file looks as follows:

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

So whatever you are trying, I don't think there is anything to change in
the code you presented, you simply need to make sure to serialize the
schema in a way such that UTF-8 is used as the encoding. My sample shows
one way with the StreamWriter.
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 12 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Almoni | last post by:
Hi, I have a few .xsd files that include each other in the following way: <!-- lets call the main schema file AA.xsd and it includes BB.xsd inside it --> <xs:schema...
0
by: Robert Jacobson | last post by:
Hi, I have a number of classes in one assembly. I'd like to use XSD.exe to generate a schema for just one class ("Parse Rules") and its nested child classes. Is there an attribute that will...
0
by: Greg | last post by:
I'm trying to read an xsd into a DataSet to generate the SQL db that I will import the data into. I get a couple errors (one of which make sense) but am not sure how to work around them I'm using...
1
by: M Ali | last post by:
Hi, I am in a situation where I don't have access to an xml, say "original.xml". But I do have the schema for it and an XSLT transformation on it that would create a new xml from "original.xml"...
2
by: PeterW | last post by:
I have an xml file from which I want to generate an xsd schema and at a later stage a cs class. The xml file has a mix of defined namespaces and also an empty namespace. These are defined as...
8
by: Phil Lee | last post by:
I'm sure this is possible but I just can't see how to do it. I want to add schemas to my solution and have C# classes automatically generated from them. I can see how to generate typed DataSet's...
2
by: Nathan Wiegman | last post by:
Hi, I am using the XSD utility to generate schemas for some of the classes that we serialize in our project. Everything works fine and dandy until I try and create a schema for a class that...
2
by: Chris Smedley | last post by:
I am attempt to perform something that I thought should be quite simple... I want to take the VoiceXML 2.0 or VoiceXML 2.1 XSD definitions and create classes. It appears that a number of items...
3
by: joshblair | last post by:
Hello, Has anyone ever seen or created such a code generator? I'm looking for a sample of a code generator that will generate code (preferably one that uses C# and the XMLTextWriter) to create...
3
fahimghauri
by: fahimghauri | last post by:
Hi, How can DDL of a schema be generated in oracle, as in DB2 db2look command provide the facility? I can generate DDL from enterprise manager, but that create generate DDL of a single table...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.