File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes validating xml against xml schema using xml spy 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 » Engineering » XML and Related Technologies
Bookmark "validating xml against xml schema using xml spy" Watch "validating xml against xml schema using xml spy" New topic

validating xml against xml schema using xml spy

prashanth nagaraj
Ranch Hand

Joined: Mar 11, 2002
Posts: 43
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 version="1.0" encoding="UTF-8"?>
<testcases xmlns:jxb="" xmlns:xsi="" xsi:noNamespaceSchemaLocation="D:\Lehman\harness\TestHarnessJava\xsd\Temp.xsd">
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:jxb="" xmlns:xsd="" elementFormDefault="qualified" jxb:version="1.0">

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

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

If anyone has any solutions please let me know

regards,<br />prashanth nagaraj
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1183
XML Spy 4.4 behaves in the same way.
The XML Schema W3C Recommendation at 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.

William Butler Yeats: All life is a preparation for something that probably will never happen. Unless you make it happen.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
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.
- madhav

I din't know I was competing with Dan. Well, I will leave this post anyways....
[ January 22, 2003: Message edited by: Madhav Lakkapragada ]

Take a Minute, Donate an Hour, Change a Life
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1183
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).
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040
Roseanne Zhang
Ranch Hand

Joined: Nov 14, 2000
Posts: 1953
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
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.
I agree. Here's the link:
subject: validating xml against xml schema using xml spy
It's not a secret anymore!