Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » ServerTools (WTP) » XML File Validation Using NameSpace
XML File Validation Using NameSpace [message #185572] Thu, 04 January 2007 19:31 Go to next message
Ben Sisson is currently offline Ben SissonFriend
Messages: 202
Registered: July 2009
Senior Member
I have a web service that I created using Eclipse 3.2 and using Apache
Tomcat 5.5.15, with Axis 1.3. I receive an xml file that I want to
validate. I had originally validated this against a schema file that I
knew would always exist using the following code:

Schema schema = this.xmlSchemalValidation(schemaName);

if (schema == null)
{
return ret_val = BASS_Enumerations.UNDEFINED_ERROR;
}
try
{
Validator v = schema.newValidator();
v.validate(new StreamSource(xml));
}

which worked fine. Then I was informed that I couldn't use the schema
Name all the time that I needed to use the references in the name space to
validate because they would very some times. I then changed the code to
the following:

// Create URL String from incoming file
String url = "file:" + xml;

final String JAXP_SCHEMA_LANGUAGE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";
final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";

try
{
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
factory.setIgnoringElementContentWhitespace(true);
factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
DocumentBuilder builder = factory.newDocumentBuilder();
MyDefaultHandler dh = new MyDefaultHandler();
builder.setErrorHandler(dh);
Document validDoc = builder.parse(url);
if (!dh.isValid)
ret_val = BASS_Enumerations.UNDEFINED_ERROR;
}

My understanding was that this would read the schemas specified in the XML
file for valdiation. However, I get the following error:

SAXParseException Error MyDefaultHandler(): cvc-elt.1: Cannot find the
declaration of element 'BOM'.

The XML file looks simlar to this:

<?xml version="1.0" encoding="UTF-8"?>
<!--Created by BOMworks version 1.0-->
<BOM xmlns="http://www.sisostds.org/schemas/bom"
xmlns:omt="http://www.sisostds.org/schemas/IEEE1516.2-2006"
xmlns:modelID="http://www.sisostds.org/schemas/modelID"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:bw="http://www.simventions.com/schemas/bomworks"
xsi:schemaLocation="http://www.sisostds.org/schemas/bom BOM_v2006.xsd
http://www.simventions.com/schemas/bomworks bomworks.xsd">
<modelIdentification>
..
..
..
</BOM>

From what I read it apperars to be setup correctly. I would appreciate
any adivce that you can provide. I notice that the element that it
specifies in the error message is the same as the name space.

Thanks,
Ben
Re: XML File Validation Using NameSpace [message #185669 is a reply to message #185572] Fri, 05 January 2007 20:59 Go to previous message
Eclipse UserFriend
Originally posted by: dcarver.starstandard.org

The namespace is not ment to be a physical location where you can download
the schema. You may need to have an XML Catalog that relates a particular
namespace to a particular XML Schema file. The other option is to use
the schemaLocation attribute to determine which schema file to be used,
but this is only a hint. Your better option is to use the Namespace if
possible and an XML Catalog.

Dave
Previous Topic:Extend/use editor in custom plugin (XMLMultiPageEditorPart)
Next Topic:Why is setting up project dependencies so hard?
Goto Forum:
  


Current Time: Fri Apr 26 23:14:26 GMT 2024

Powered by FUDForum. Page generated in 0.04168 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top