Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

xsi:type As attribute name for element

 
Malatesh Karabisti
Ranch Hand
Posts: 153
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
g tsuji
Ranch Hand
Posts: 656
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic