473,799 Members | 3,298 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 CreateSchemaRoo t()
{
schema.ElementF ormDefault = XmlSchemaForm.N one;
schema.Attribut eFormDefault = XmlSchemaForm.U nqualified;
schema.Version = "1.0";
XmlSerializerNa mespaces ns = new XmlSerializerNa mespaces();
ns.Add("xsd", schemaNS);
schema.Namespac es = ns;
return schema;
}

Nov 12 '05 #1
1 4183


co********@yaho o.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 CreateSchemaRoo t()
{
schema.ElementF ormDefault = XmlSchemaForm.N one;
schema.Attribut eFormDefault = XmlSchemaForm.U nqualified;
schema.Version = "1.0";
XmlSerializerNa mespaces ns = new XmlSerializerNa mespaces();
ns.Add("xsd", schemaNS);
schema.Namespac es = 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();

XmlSchemaElemen t elementGod = new XmlSchemaElemen t();
elementGod.Name = "God";
elementGod.Sche maTypeName = new XmlQualifiedNam e("string",
XmlSchema.Names pace);

exampleSchema.I tems.Add(elemen tGod);

exampleSchema.C ompile(new ValidationEvent Handler(Validat ionHandler));

XmlNamespaceMan ager namespaceManage r = new XmlNamespaceMan ager(new
NameTable());
namespaceManage r.AddNamespace( "xs", XmlSchema.Names pace);

using (StreamWriter schemaWriter = new
StreamWriter(@" test2005102601X sd.xml")) {
exampleSchema.W rite(schemaWrit er, namespaceManage r);
}

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
2418
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 xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
0
1748
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 allow me to do this? I tried running XSD on the entire assembly, with the plan to delete the unnecessary classes from the .xsd afterwords. However, it complained that a certain class "cannot be serialized because it does not have a default...
0
3607
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 XmlDataDocument.DataSet.ReadXmlSchema() to try to read the schema at http://www.ordnancesurvey.co.uk/oswebsite/xml/schema/v3/OSDNFFeatures.xs I get an error stating 'System.ArgumentException: The same table (boundedBy) cannot be the child table...
1
1429
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" called "transform.xml". What i need is the schema for the "transform.xml". I could generate the schema from the xml if I had "transform.xml". But I don't have access to "original.xml" so I cannot apply the transform to get
2
6935
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 follows: <silcn:silcn xmlns:silcn='http://silcn.org/200309' xmlns='http://xmlprobe.com/200312'> it contains an element <report> off the root and also a separate <Silcn:report> again off the root.
8
6461
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 with the MSDataSetGenerator custom tool. Is there something similar for simple schemas? Regards Phil Lee
2
3541
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 spans assemblies. For example, if I have a class named "ClassB" that resides in "ClassB.exe" and uses stuff (classes) from "ClassC.dll", I would expect the following to work:
2
2724
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 are not included in the definitions of either version of VoiceXML and I find this unlikely. For VoiceXML 2.0 I used http://www.w3.org/TR/voicexml20/#dmlASchema and downloaded the complete schema within a zip file:
3
2066
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 an XML document structure based on an XML file as input. I have to build some classes that allow me to generate some very complex/large/nasty XML documents for use in B2B exchange of data (like
3
9337
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 and also does not generate DDL of Foreign keys. Regards, Fahim
0
9546
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10030
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7570
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4146
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3762
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.