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">
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.
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 ]
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.
subject: validating xml against xml schema using xml spy