Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


XML Schema Instance Namespace Dropping

Posted on 2011-04-25
Medium Priority
Last Modified: 2012-06-22
Having an issue here and think it’s something I'm missing with XSD, probably a misunderstanding of XML Schema on my part. Attached is an example Person.xsd and Auto.xsd. Can anyone tell me why when I generate an instance of Person.xsd using a tool like StylusStudio I get a Person xml with an Auto xml using the same namespace as Person (Person.xml)? I was expecting to get an xml instance as such (notice the p2 namespace provided for auto and different than p1:

<?xml version="1.0"?>
<p1:Person xmlns:p1=http://www.company.com/person xmlns:p2="http://www.company.com/auto" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.company.com/person file:///c:/Documents%20and%20Settings/btaylor/Desktop/Person.xsd">
    <p2:Auto make="string">
        <!--Attribute make is optional-->


Question by:softechnics
  • 3
  • 2

Author Comment

ID: 35460945
I think we figured it out. It appears that, unlike Java packages, object instances (<element>) are of the namespace they’re used, not defined. Therefore the following is a valid <Person> instance:

<?xml version="1.0"?>
<p1:Person xmlns:p1=http://www.company.com/person>
    <p1:Auto make="string"/>


<?xml version="1.0"?>
<p1:Person xmlns:p1=http://www.company.com/person xmlns:p2="http://www.company.com/auto">
    <p2:Auto make="string"/>
LVL 60

Accepted Solution

Geert Bormans earned 1000 total points
ID: 35464760
This is a tricky example you have here.
The type reference is to the "../auto" namespace (you have type="a:Auto" in the schema)
but the element Auto is created inside the person namespace
<xsd:element name="Auto" type="a:Auto" minOccurs="1" maxOccurs="1"/>
creates a element "Auto" in the active targetNamespace "../person"
Maybe what you wanted to do (what would make more sense) is "reference" the allready created auto element in the auto namespace
This is definitely how I would do it
                        <xsd:element ref="a:Auto" minOccurs="1" maxOccurs="1"/>
now refers to the Auto element that is declared in the auto namespace

Note that your two current schema's declare two Auto elements, one global in the auto namespace and on local inside person in the person namespace

If you change the one line that I chaged, making the local element declaration an element reference,
this is valid

<p1:Person xmlns:p1="http://www.company.com/person"
    xsi:schemaLocation="Person.xsd" xmlns:p2="http://www.company.com/auto">
    <p2:Auto make="string"/>

And that is definitely how I would model that

LVL 60

Assisted Solution

by:Geert Bormans
Geert Bormans earned 1000 total points
ID: 35464831
To sort of use your terminology:

you think you "use" an element that is defined elswhere,
but instead you "define" a new one

Author Closing Comment

ID: 35466624
Excellent response and thank you much Gertone!
LVL 60

Expert Comment

by:Geert Bormans
ID: 35466637

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Integration Management Part 2
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question