[jdom-interest] validation problem

Li Xu Lxu at copyright.com
Mon Jul 22 12:31:23 PDT 2002


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>
====
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://jdom.org/pipermail/jdom-interest/attachments/20020722/fca144ff/attachment.htm


More information about the jdom-interest mailing list