Link to home
Start Free TrialLog in
Avatar of softechnics
softechnics

asked on

XML Schema Instance Namespace Dropping

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-->
    </p2:Auto>
</p1:Person>

Respectfully,

Brian
Auto.xsd
Person.xsd
Person.xml
Avatar of softechnics
softechnics

ASKER

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"/>
</p1:Person>

Not:

<?xml version="1.0"?>
<p1:Person xmlns:p1=http://www.company.com/person xmlns:p2="http://www.company.com/auto">
    <p2:Auto make="string"/>
</p1:Person>
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Excellent response and thank you much Gertone!