Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validating xml against xml schema using xml spy

 
prashanth nagaraj
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , I am using XML SPY version5 Professional Edition , evaluation copy in my project development.
I am using anyType as type for some elements.
For this type(anyType) , I can add either test between the elements or child elements itself.
While validating the xml against the xml schema using jaxb , this is working fine.
But if I validate using XML schema , the XML SPY expects anyType as string only.
Is there any way from which I can configure within XML SPY so that a user can give anything (both elements and text).
See the following examples:
This xml validates using JAXB. But not in XML SPY.
If I remove the child element<anyelement> and put some text it will validate
XML FILE
<?xml version="1.0" encoding="UTF-8"?>
<testcases xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="D:\Lehman\harness\TestHarnessJava\xsd\Temp.xsd">
<testcase>
<value><anyelement>hjer</anyelement></value>
</testcase>
</testcases>
XSD FILE
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" jxb:version="1.0">

<xsd:element name="testcases">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="testcase" type="testcasetype"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

<xsd:complexType name="testcasetype">
<xsd:sequence>
<xsd:element name="value" type="xsd:anyType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>

If anyone has any solutions please let me know
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
XML Spy 4.4 behaves in the same way.
The XML Schema W3C Recommendation at http://www.w3.org/TR/xmlschema-0/#anyType says -
2.5.4 anyType
The anyType represents an abstraction called the ur-type which is the base type from which all simple and complex types are derived. An anyType type does not constrain its content in any way. It is possible to use anyType like other types, for example:
<xsd:element name="anything" type="xsd:anyType"/>
The content of the element declared in this way is unconstrained, so the element value may be 423.46, but it may be any other sequence of characters as well, or indeed a mixture of characters and elements. In fact, anyType is the default type when none is specified, so the above could also be written as follows:
<xsd:element name="anything"/>
If unconstrained element content is needed, for example in the case of elements containing prose which requires embedded markup to support internationalization, then the default declaration or a slightly restricted form of it may be suitable. The text type described in Section 5.5 is an example of such a type that is suitable for such purposes.

So, XML Spy seems to be wrong.
I wonder whether Altova has an errata site for XML Spy.
Cheers,
Dan
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No solution so far, but here is my research....
1. I agree with what you said re XML Spy.
2. Acc. to the schema recommendation this is the
  definition of anyType. However, I cannot explain the lingo used. Still looking....
Hopefully someone else can explain why xsd:anyType resolves to xsd:string.
regds.
- madhav

ps:
I din't know I was competing with Dan. Well, I will leave this post anyways....
[ January 22, 2003: Message edited by: Madhav Lakkapragada ]
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Madhav,
We are not competing – competing over everything is the American way. I believe in sharing, learning from each other and challenging each other (in a positive way).
Cheers,
Dan
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Roseanne Zhang
Ranch Hand
Posts: 1953
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To my understanding, anyType could contain any mixed text and elements. However, the elements included must be declared, unless you specify processContents="lax". See here http://www.w3.org/TR/xmlschema-0/#textType
If you add this line into your schema, top level, then your XML is valid.

Learned a lot from this discussion and found two solutions.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic