473,394 Members | 1,802 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,394 software developers and data experts.

XmlSchema doesn't include default namespace

Hi,

I'm creating a component to generate a schema file much like VS generates for DataSets.

I'm using XmlSchema to do the job and I also am using a XmlNamespaceManager to manage namespaces.

XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
nsmgr.AddNamespace("msdata", "urn:schemas-microsoft-com:xml-msdata");
nsmgr.AddNamespace("mstns", "http://tempuri.org/Dataset.xsd");
nsmgr.AddNamespace(string.Empty, "http://tempuri.org/Dataset.xsd");

The trouble is that when I write out the xsd using

schema.Write(writer, nsmgr);

It doesn't include the default namespace as it is included in xsds generated by VS. I can for the life of me get it to work.

Here is the root node output:

<xs:schema targetNamespace="http://tempuri.org/Dataset.xsd" elementFormDefault="qualified" attributeFormDefault="qualified" id="Dummy" xmlns:mstns="http://tempuri.org/Dataset.xsd" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xs="http://www.w3.org/2001/XMLSchema">

It makes some parts of my resultant dataset not validate and also VS does not recognise any relation elements.

I have implemented a workaround by manually adding it after the xsd is genereted as such:

doc.Load(filename);
XmlElement root = doc.DocumentElement;
XmlAttribute attrib = doc.CreateAttribute("xmlns");
attrib.Value = nsmgr.DefaultNamespace;
root.Attributes.Append(attrib);
XmlWriter writer = new XmlTextWriter(allTablesFileName, Encoding.UTF8);
doc.WriteTo(writer);
writer.Close();

This then matches the dataset xsd as such:

<xs:schema targetNamespace="http://tempuri.org/Dataset.xsd" elementFormDefault="qualified" attributeFormDefault="qualified" id="DataSet" xmlns:mstns="http://tempuri.org/Dataset.xsd" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/Dataset.xsd">

Now the xsd looks just like a dataset xsd, and validates and can be loaded in VS as normal.

Does any one know why the default namespace is not being included (it does if the prefixed namespace with the same namespace is not included in the namespace manager), and if there is a better workaround than I have done.

Thank you,

John
Nov 12 '05 #1
0 1317

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

Similar topics

4
by: Robert Ludewig | last post by:
This is my XML Schema (Sitemap.xsd) : <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.htw-dresden.de/SitemapNS">...
2
by: AlexS | last post by:
Hello, I have error when reading schema using XmlSchema. Read and then .Compile: System.Xml.Schema.XmlSchemaException: May not be nominated as the {substitution group affiliation} of any...
3
by: Nathan Wallace | last post by:
Hello, I have 2 schema, for argument sake let's call them child.xsd and parent.xsd. I define all my types in parent.xsd and the child.xsd include the parent.xsd using the following tag: ...
1
by: qdm | last post by:
Below is a snippet that I'm sure is quite familiar to most ... <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" Here, I've given the XMLSchema namespace the prefix 'xsd', and with...
1
by: Rumen Traykov via .NET 247 | last post by:
Have somebody had already the problem of having to write more than one XmlSchema, where some of these schemas have imports to others and respectively derived types? The imports cannot be resolved...
4
by: Igor Koretsky | last post by:
Hi. Using VB.Net System.Xml 1.0 SchemaCollection Object I am getting an error when trying to add ‘Schema A’ to the SchemaCollection. Here are my schema files..
2
by: doughboy | last post by:
I create a schema in memory and then I can write to a file fine. But as soon as I add an import element I get an error when it goes to write to the file. The error message is: The type...
3
by: JMD | last post by:
A set of xsd files has been working fine for us at this site, but now it gives *intermittent* errors for someone at a different cite (who is consuming the code we are producing). Most of the time...
1
by: Ryan | last post by:
Hello Xml Gurus, I'm trying to build an XML schema in memory using the System.Xml.XmlSchema namespace objects, validate it, and then write it to a file. The problem I'm facing is that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.