xsd creation where xml has as multiple namespaces

I luck quite significant knowledge with xsd files. my question may be unclear or silly... but i need help.

i have an xml that loos as below. What i need is that the xsd that i use, allows the node's
<mx:String value="plugins"> .

But, when i try to add an element with name "mx:string" it does not let me..
I have tried to add the namespace of mx inside my xsd but could not... (if this is the correct way, lets discuss how this can be done).
I have tried to create a second xsd, that my xsd will import and use. the second xsd would have namespace mx, but this did not help either (if this is the way, lets talk on how this can be done).

Other ways? Any correct/easy and clean way?

Cheers
<plugin:Plugin>
   <properties>
      bla bla bla
   <properties>
   <toolbar>
      <mx:String value="plugins"> 
      <mx:String value="all">
       ...
   <toolbar>

Open in new window

RongasAsked:
Who is Participating?
 
Geert BormansInformation ArchitectCommented:
In this particular example, toolbar is in the null namespace and String is in the mx namespace,
that is not very good policy.
I suspect toolbar should be in a namespace of its own, though defaulted.

Here are some suggestions for doing that, note that quiet a bit changes
The mx schema is not repeated since it stays the same
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8"?>
<toolbar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="urn:toolbar toolbar.xsd"
    xmlns:mx="urn:mx"
    xmlns="urn:toolbar"> 
    <mx:String value="plugins"/>  
    <mx:String value="all"/> 
</toolbar>

XSD
---
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:mx="urn:mx"
    xmlns="urn:toolbar"
    targetNamespace="urn:toolbar">
    <xs:import namespace="urn:mx" schemaLocation="mx.xsd"/>
    <xs:element name="toolbar">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="mx:String" maxOccurs="unbounded"></xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

Open in new window

0
 
Geert BormansInformation ArchitectCommented:
Well, every namespace in your document should be the targetNamespace of a seperate schema
This implies that you need a seperate schema documument per namespace
and that you need to import the corrct bits at the right place.

It is clean but not so easy. Multiple namespace schemas are a bit advanced
I will show you an example in a minute

Can you show the namespace declarations for the prefixes? That would make the schema more ready to use for you
0
 
marklorenzCommented:
You have to have a namespace declared for "mx".  Check out the details here:

http://www.w3schools.com/schema/schema_schema.asp
http://www.oracle.com/technology/pub/articles/srivastava_namespaces.html
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
Geert BormansInformation ArchitectCommented:
> I have tried to create a second xsd, that my xsd will import and use. the second xsd would have namespace mx

That is the correct way

See examples in the below code pane
XML
---
<?xml version="1.0" encoding="UTF-8"?>
<toolbar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="toolbar.xsd"
 xmlns:mx="urn:mx"> 
    <mx:String value="plugins"/>  
    <mx:String value="all"/> 
</toolbar>

XSD: toolbar.xsd
----------------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:mx="urn:mx">
    <xs:import namespace="urn:mx" schemaLocation="mx.xsd"/>
    <xs:element name="toolbar">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="mx:String" maxOccurs="unbounded"></xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

XSD: mx.xsd
-----------
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="urn:mx"
    xmlns:mx="urn:mx">
    <xs:element name="String">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string">
                    <xs:attribute name="value"/>
                </xs:extension>
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>
</xs:schema>

Open in new window

0
 
Geert BormansInformation ArchitectCommented:
Once you have elements in a namespace, try to have all of them in a namespace
0
 
RongasAuthor Commented:
perfect... :-) sorry for the delay on answering
0
 
Geert BormansInformation ArchitectCommented:
welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.