XML Schema Instance Namespace Dropping

Posted on 2011-04-25
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= xmlns:p2="" xmlns:xsi="" xsi:schemaLocation=" file:///c:/Documents%20and%20Settings/btaylor/Desktop/Person.xsd">
    <p2:Auto make="string">
        <!--Attribute make is optional-->


Question by:softechnics

    Author Comment

    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=>
        <p1:Auto make="string"/>


    <?xml version="1.0"?>
    <p1:Person xmlns:p1= xmlns:p2="">
        <p2:Auto make="string"/>
    LVL 60

    Accepted Solution

    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=""
        xsi:schemaLocation="Person.xsd" xmlns:p2="">
        <p2:Auto make="string"/>

    And that is definitely how I would model that

    LVL 60

    Assisted Solution

    by:Geert Bormans
    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

    Excellent response and thank you much Gertone!
    LVL 60

    Expert Comment

    by:Geert Bormans

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    759 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

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now