Results 1 to 5 of 5
- 11-02-2010, 09:35 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
Validator.validate() fails when using DOM Document instead of File
Dear Java Community:
I have had a heck of a time tracking down the problem I am seeing. I am trying to validate a DOM Document with a Namespace against a XSD Schema. I am attempting to use the javax.xml.validation package with Java 6. No matter what I do I keep getting the following exception. Please help.
Exception:
cvc-elt.1: Cannot find the declaration of element 'k4Object': where 'k4Object' is my root element.
DOM Document with a Namespace:
Java Code:<?xml version="1.0" encoding="UTF-8"?> <k4Object xmlns="http://www.company.com/InPorterIntermediate"> <k4Server name="Tech_K4_6" url="http://eng10as:8080/K4/"/> <k4Login password="x4" username="admin"/> <template id="-1" name=""/> <publication id="1280178296340" name="InPortTesting"/> <issue dynamic="" id="1510" name="Testing 2"/> <section id="7" name="Editorial"/> <notes value=""/> <workflow id="4654" name="Article"/> <outputChannel id="4518" name="Print"/> <variant id="-1" name=""/> </k4Object>
Validation source code snippet:
Java Code:DocumentBuilderFactory dbf; dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); Document newDoc = db.newDocument(); //inXMLNode is the XML structured above newDoc.appendChild(newDoc.importNode(inXMLNode, true)); //Lookup a factory for the W3C XML Schema language SchemaFactory factory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema"); //Compile the schema. //Here the schema is loaded from a resource InputStream schemaLocation = this.getClass().getResourceAsStream("/InPorterIntermediate.xsd"); Source schemaSource = new StreamSource(schemaLocation); Schema schema = factory.newSchema(schemaSource); //Get a validator from the schema. Validator validator = schema.newValidator(); Source source = new DOMSource(newDoc); validator.validate(source); log.info("Merged document is valid.");
The most disturbing fact is that I have this exact same code in another location that works fine. The difference is that instead of using Source source = new DOMSource(newDoc), I am using Source source = new StreamSource(file). I can't transform my DOM Document to a file and use that since doing a transformation on it would also not be namespace aware.
Note: If I put the XML into and editor like oXygen and create a validation scenario with my physical XSD Schema file it states the XML is valid.
Please give me some assistance, any information would be of great use. Thank you.
Sincerely,
Mike Sucena
- 11-03-2010, 09:40 PM #2
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
Please help
Does anyone have anything to say about this?
- 11-04-2010, 08:32 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Didn't you ask this on the Oracle forum?
- 11-04-2010, 02:10 PM #4
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
Couldn't create an account
Oracle forums wouldn't let me create an account when I tried. I guess it would probably be better asked there, I guess I'm going to have to try it again.
- 11-04-2010, 02:41 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Similar Threads
-
Validate a Zip file with java
By peuplier in forum Advanced JavaReplies: 1Last Post: 07-10-2009, 10:07 PM -
Validate document starting at xpath
By sarcasteak in forum Advanced JavaReplies: 1Last Post: 04-16-2009, 01:22 AM -
How to parse the CSV(Comma separation values)file and validate the file using java
By padmajap13 in forum Advanced JavaReplies: 7Last Post: 05-23-2008, 03:46 AM -
how to validate a xml file with schemas via SAX
By oregon in forum XMLReplies: 3Last Post: 08-01-2007, 05:15 PM -
Struts Validator - JScript version of Validator ´validwhen´
By Felissa in forum Web FrameworksReplies: 1Last Post: 07-06-2007, 04:39 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks