473,787 Members | 2,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Confused about namespace in XML schema and in XML instance doc

Hello, need some help to understand this.(I am using DevSutio.Net)

I set the default name space to be "http://www.w3.org/2001/XMLSchema"
in my XML schema and I use my XML schema as the default namespace in
XML instance doc. But it turns out to invlaid. Need some help to
understand why.

Many thanks

///// Here is my schema
<?xml version="1.0" encoding="utf-8" ?>
<schema targetNamespace ="http://tempuri.org/XMLSchema.xsd"
xmlns:jchen="ht tp://tempuri.org/XMLSchema.xsd"
xmlns="http://www.w3.org/2001/XMLSchema"> <<=I made this as my
default namespace
<complexType name="personTyp e">
<sequence>
<element name="FirstName " type="string" />
<element name="LastName" type="string" />
</sequence>
</complexType>
<complexType name="peopleTyp e">
<sequence maxOccurs="unbo unded">
<element name="Person" type="jchen:per sonType" />
</sequence>
</complexType>
<element name="People" type="jchen:peo pleType"></element>
</schema>

//// I then test my schema in DevStudio.Net and it becomes invalid
<?xml version="1.0" encoding="utf-8" ?>
<People xmlns="http://tempuri.org/XMLSchema.xsd"> <<=Use my schema as
default
<Person>
<FirstName> Jamie </FirstName>
<LastName> Chen </LastName>
</Person>
<Person>
<FirstName> Jonathan </FirstName>
<LastName> Chen </LastName>
</Person>
<People>

///// Person tag cannnot be found, this is very strange
Jul 20 '05 #1
2 1392
In article <d8************ **************@ posting.google. com>,
Jamie Chen <ja*******@hotm ail.com> wrote:
<complexType name="peopleTyp e">
<sequence maxOccurs="unbo unded">
<element name="Person" type="jchen:per sonType" />


This declares a local element "Person". By default, local element
declarations apply to elements in no namespace.

You have used the (more common) convention of having all your elements
in the same namespace, rather than making the non-top-level ones be in
no namespace. So you need to add an attribute
elementFormDefa ult="qualified" to the schema element. (Or you could
add elementForm="qu alified" to the local element declaration, but if
you're going to follow the usual convention it's simpler to set the
default at the top.)

-- Richard
Jul 20 '05 #2
Hi,

Your "Person" element is locally declared, which means that by default
it should be in no namespace. In your instance, since you use a default
namespace declaration, the Person element is considered to be in that
namespace, hence the mismatch.

You have two choices:

1. Add elementFormDefa ult="unqualifie d" to your schema element.

2. Change your instance so it looks like this, with a prefix defined and
the prefix only on the root element:

<ex:People xmlns:ex="http://tempuri.org/XMLSchema.xsd">
<Person>
<FirstName> Jamie </FirstName>
<LastName> Chen </LastName>
</Person>
<Person>
<FirstName> Jonathan </FirstName>
<LastName> Chen </LastName>
</Person>
<ex:People>

Hope that helps,
Priscilla
-----------------------------------------------------
Priscilla Walmsley pr*******@walms ley.com
Author, Definitive XML Schema (Prentice Hall PTR)
-----------------------------------------------------

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #3

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

Similar topics

3
1458
by: Koen De Wolf | last post by:
Dear all, I have the following problem In a schema I refer to a type in a different schema like this: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified" targetNamespace="http://www.example.com" xmlns:test="test">
2
1935
by: Zombie | last post by:
Hi all, I wish to create a namespace other than the default one. Let's say, the Schema looks like: ----------------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:d="http://www.geodesy.org/dam" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified"> <xs:element name="River">
1
2238
by: Steve George | last post by:
Hi, I have a scenario where I have a master schema that defines a number of complex and simple types. I then have a number of other schemas (with different namespaces) where I would like to reuse some of these master complex and simple types. This I believe will assist me in transforming between the master schema and the other smaller schemas that contain a subset of the elements in the master schema. I understand that I can import an...
0
1708
by: Alberto Grosso Nicolin | last post by:
We have the following XML schema: there's a root element (Response) with of a single child element (Result). ---------------------------------------------------------------------------------------------- <?xml version="1.0" encoding="utf-8"?> <xs:schema id="TaskRequest" targetNamespace="http://xyz.com/TaskResponse/1.0" elementFormDefault="qualified" xmlns="http://xyz.com/TaskResponse/1.0"
2
4566
by: tomek.romanowski | last post by:
Hi ! I have problem with validating of the document with multiple namespaces. The odd thing is, that my data work O'K when I test it under XMLSpy but it doesn't work with my C# code. My first 'main' schema is as follows: incr2.xsd ---------- <xs:schema targetNamespace="http://vit.volvo.com/dept9272/2004/ESB"
1
1580
by: mflll | last post by:
How does one say in one schema that one wants an element defined in another schema. For example, I want to include in the Employee definition, an Address element defined in the schema http://test.org.Address Here is the schema defining the Employee: <?xml version="1.0" encoding="UTF-8"?> <xsd:schema targetNamespace="http://test.org/emp" xmlns="http://test.org/emp"
2
3047
by: Mark | last post by:
Hi... I've been trying the .Validate() method on the XmlDocument to validate some xml against a schema, but one thing I noted was that unless the document explicitly declares the schema as a default namespace, Validate() just lets it slide through as a success. Is there a way to Validate() either a) mandating against a particular schema, or at the very least b) supplying a default namespace to be used even when not explicitly declared?
3
8130
by: bhu | last post by:
Hi i am trying some things in XML for webservices but got stuck with the xml Creation. This is the First Sample C# Code XmlDocument oInvDocument = new XmlDocument(); oNode= oInvDocument.CreateNode(XmlNodeType.Element,"InventoryUpdateBatch",""); oInvDocument.AppendChild(oNode);
6
4277
by: burkley | last post by:
In XML Schema, is it possible to derive a complex type via restriction and have the new derived type be in a different namespace than the original base type? I've banged on this for 2 days now and I'm starting to think the answer is no. I've searched this group and have not seen anything discussing this. the base type. All values of the restricted type are also valid according to the base type".
0
10363
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
10169
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...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
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
7517
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
6749
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
5398
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4067
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

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.