473,657 Members | 2,458 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 XmlNamespaceMan ager to manage namespaces.

XmlNamespaceMan ager nsmgr = new XmlNamespaceMan ager(nt);
nsmgr.AddNamesp ace("xs", "http://www.w3.org/2001/XMLSchema");
nsmgr.AddNamesp ace("msdata", "urn:schema s-microsoft-com:xml-msdata");
nsmgr.AddNamesp ace("mstns", "http://tempuri.org/Dataset.xsd");
nsmgr.AddNamesp ace(string.Empt y, "http://tempuri.org/Dataset.xsd");

The trouble is that when I write out the xsd using

schema.Write(wr iter, 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" elementFormDefa ult="qualified" attributeFormDe fault="qualifie d" id="Dummy" xmlns:mstns="ht tp://tempuri.org/Dataset.xsd" xmlns:msdata="u rn: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(filena me);
XmlElement root = doc.DocumentEle ment;
XmlAttribute attrib = doc.CreateAttri bute("xmlns");
attrib.Value = nsmgr.DefaultNa mespace;
root.Attributes .Append(attrib) ;
XmlWriter writer = new XmlTextWriter(a llTablesFileNam e, Encoding.UTF8);
doc.WriteTo(wri ter);
writer.Close();

This then matches the dataset xsd as such:

<xs:schema targetNamespace ="http://tempuri.org/Dataset.xsd" elementFormDefa ult="qualified" attributeFormDe fault="qualifie d" id="DataSet" xmlns:mstns="ht tp://tempuri.org/Dataset.xsd" xmlns:msdata="u rn: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 1346

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

Similar topics

4
2043
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"> <xs:element name="Sitemap"> <xs:complexType> <xs:all> <xs:element name="Page"> <xs:complexType>
2
9078
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 other declaration. An error occurred at , (11, 3). Schema compile error: System.Exception: Schema error ---> System.Xml.Schema.XmlSchemaException: May no
3
2804
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: <xs:include schemaLocation="http://localhost/xsds/parent.xsd"/> Now when I create an XmlSchema object on the child.xsd I couldn't get the type that I define in the parent.xsd. How do I get this? Do I need to create
1
1392
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 that, I can reference datatypes within the XMLSchema namespace ... i.e., xsd:string. That's great, but why can't I use that same notation, to reference dataypes in a homegrown schema ... WITHOUT doing an <import> or
1
1528
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 until I dont save all schemas to disk, but I cannot do this because I get an error for the derived types(which have base types from schema which is not written yet, so the import cannot be resolved). How could I solve this problem? I dont need any...
4
1648
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
2171
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 System.Xml.Schema.XmlSchemaImport was not expected. Use the XmlInclude or SoapInclude attribute to specify types that are not known statically. What does this mean? Is there a limitation to when I can use
3
4481
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 it works fine. Occasionally it gives an error in the schema compiler: "System.Xml.Schema.XmlSchemaException: Wildcard '##other' allows element 'Page', and causes the content model to become ambiguous. A content model must be formed such that...
1
4020
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 XmlSchema.Write() is changing <xsd:element minOccurs="1" name="AccountId" type="s-xsd:primarykey" /> to be
0
8420
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
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
8842
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8617
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
7353
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...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
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
1970
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1733
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.