You can ignore my previous post. I was
right – I *was* missing
something dumb. I didn’t have the namespace in the
externalSchemaLocation property. From: Robert Houben
[mailto:[EMAIL PROTECTED] I’m having trouble validating my XML with an external
XSD when I add a namespace. I’ve looked at all the related posts on
the archives and cannot see what I’m doing wrong. Probably too many
trees in my forest! ;) I get this error: cvc-elt.1: Cannot find the
declaration of element 'outer'. Here is the XSD: <s:schema
xmlns:s="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://rhtest"
elementFormDefault="qualified" > <s:element name="outer">
<s:complexType>
<s:sequence>
<s:element
name="middle">
<s:complexType>
<s:sequence>
<s:element name="inner" />
</s:sequence>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType> </s:element> </s:schema> Here is the instance (note the commented variation
didn’t work, either):
<!--
<x:outer xmlns:x="http://rhtest">
<x:middle>
<x:inner/>
</x:middle>
</x:outer>
-->
<outer xmlns="http://rhtest">
<middle>
<inner/>
</middle>
</outer> And here is my code:
public void loadXML(String xmlString, String externalSchemaLocation, String
namespace) throws FWTransactionException
{
DOMParser parser = new DOMParser();
try
{
parser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage",
"http://www.w3.org/2001/XMLSchema");
parser.setFeature(
"http://apache.org/xml/features/validation/schema", true);
parser.setFeature(
"http://apache.org/xml/features/validation/schema-full-checking",
true);
parser.setFeature("http://xml.org/sax/features/namespaces",true);
parser.setFeature("http://xml.org/sax/features/validation",true);
parser.setErrorHandler(this);
if (null == namespace || namespace.length() == 0)
{
parser.setProperty(
"http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
externalSchemaLocation.replace('\\', '/'));
}
else
{
parser.setProperty(
"http://apache.org/xml/properties/schema/external-schemaLocation",
externalSchemaLocation.replace('\\', '/'));
}
parser.parse(new InputSource(new ByteArrayInputStream(xmlString.getBytes())));
}
catch (SAXNotRecognizedException snre)
{
//
}
catch (SAXNotSupportedException snre)
{
//
}
catch (SAXException se)
{
//
}
catch (IOException ioe)
{
//
}
} TIA, |
- Validating XML: I'm missing something... Robert Houben
- RE: Validating XML: I'm missing something... Robert Houben