File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "xsi:type  As attribute name for element" Watch "xsi:type  As attribute name for element" New topic

xsi:type As attribute name for element

Malatesh Karabisti
Ranch Hand

Joined: Jul 28, 2010
Posts: 153


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
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:
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 633
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:
subject: xsi:type As attribute name for element
It's not a secret anymore!