[jdom-interest] validation problem
Clint M. Frederickson
clintf at neo.cs.montana.edu
Mon Jul 22 12:57:07 PDT 2002
I have created a small webpage that may be able to help you. Please
visit http://cs.montana.edu/%7Efrederic/xmlGuide/index.html There you
will find a couple of examples of how to do schema validation.
Hope this is helpful,
--Clint M. Frederickson
On Mon, 2002-07-22 at 13:31, Li Xu wrote:
> Hi,
>
> New jdom user here. I try to validate some XML against a schema...
>
> SAXBuilder sb = new SAXBuilder(true);
> Document d = sb.build(new java.net.URL("file://C:/Test/src/test.xml"));
>
> throws exception about "Element 'response' used but not declared". The same two files validate just fine in XMLSpy IDE. Can someone help me?
>
> PS, when I add a child element (without namespace) using Element.addContent(Element), it automatically inserts xmlns="" into the child element when the parent namespace is not empty. Why is that happening?
>
> Thank you!
>
>
> Here's test.xml:
> ====
> <?xml version="1.0" encoding="UTF-8"?>
> <response xmlns="http://my.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://my.com
> C:\Test\src\test.xsd">
> <stuff>String</stuff>
> </response>
> ====
>
> test.xsd:
> ====
> <?xml version="1.0" encoding="UTF-8"?>
> <xsd:schema targetNamespace="http://my.com" xmlns="http://my.com" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
> <xsd:complexType name="error_TYPE">
> <xsd:sequence>
> <xsd:element name="error_code" type="xsd:string"/>
> <xsd:element name="error_detail" type="xsd:string"/>
> <xsd:element name="error_level" type="xsd:unsignedShort" minOccurs="0"/>
> </xsd:sequence>
> <xsd:attribute name="id" type="xsd:unsignedLong" use="required"/>
> </xsd:complexType>
> <xsd:element name="response">
> <xsd:complexType>
> <xsd:choice>
> <xsd:element name="stuff" type="xsd:string"/>
> <xsd:element name="error" type="error_TYPE" maxOccurs="unbounded"/>
> </xsd:choice>
> <xsd:attribute name="mode" use="optional">
> <xsd:simpleType>
> <xsd:restriction base="xsd:string">
> <xsd:enumeration value="PROD"/>
> <xsd:enumeration value="DEMO"/>
> </xsd:restriction>
> </xsd:simpleType>
> </xsd:attribute>
> </xsd:complexType>
> </xsd:element>
> </xsd:schema>
> ====
More information about the jdom-interest
mailing list