aspose file tools*
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
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
Author

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 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


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

Joined: Jul 09, 2001
Posts: 1174
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


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.
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 ]

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Dan Drillich
Ranch Hand

Joined: Jul 09, 2001
Posts: 1174
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

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 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validating xml against xml schema using xml spy