my dog learned polymorphism*
The moose likes Web Services and the fly likes xsi:type  As attribute name for element Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "xsi:type  As attribute name for element" Watch "xsi:type  As attribute name for element" New topic
Author

xsi:type As attribute name for element

Malatesh Karabisti
Ranch Hand

Joined: Jul 28, 2010
Posts: 153

Hi,

I am writing the XSD for XML sample as shown below I am in need of using the xsi:type as attribute name.


Sample XML

<testschema:criteria xsi:type="testschema:simple" >

Can any body please explain how can write the XSD for this XML ?

I have tried like. It is now working
<xs:attribute name="xsi:type" form="unqualified" type="xs:string" />

I mean is there a way to include the "xsi:" in my attribute's name
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Why do you want to include a specific namespace-attribute in your attribute's name?
As I am sure you already are aware of, the construct "aaa:bbb" is used to specify a namespace prefix (aaa) of some symbol (bbb).
When you declare an attribute, you declare it as belonging to a namespace. Later, when you or someone else uses that attribute, it may or may not be prefixed with a namespace attribute - it depends on the namespace declarations in the XML document being written. Thus you can never force a certain namespace prefix, if that is what you had in mind.
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 499
    
    3
I have tried like. It is now [not?] working
<xs:attribute name="xsi:type" form="unqualified" type="xs:string" />

It won't work that way. There is typically no need to provision xsi:type in the schema for its appearance in an instance document - just like you don't need to make it into the schema any xsi:schemaLocation etc.

What you need to do - and that is important - is to provision a top-level xs:complexType or xs:simpleType (according to your actual case) named "simple". The targetNamespace of that xs document should be coincide with the one that testschema in the instance document. xsi:type is trying to resolve the need in some cases where some elements of the same name in the same scope require to be allowed to be of some quite different type in the instance document.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xsi:type As attribute name for element
 
Similar Threads
JAXB namespace use in XML files
Have a question about accessing the SOAP response via VBA client.
selecting encoding style of soapenc vs xsd
Exception: java.lang.illegal Argument Exception
SOAP-ENC:Array instance validation