Results 1 to 2 of 2
  1. #1
    devin is offline Member
    Join Date
    Feb 2009
    Rep Power

    Default XML Schema validation


    I am having some problems validating XML against a schema. I have an XML document and a very simple schema file, when I run it against the code below it fails. However, when I manually add my schema definition to my XML file and run "Validate XML" in Netbeans it passes. The validation is complaining about the root node not being defined. This is the same error you get in Netbeans when you don't define a schema. Is there something else I have to do to make validate use my schema file? I don't want to define the schema definition in the XML file because I am validating XML files that I have no control over.

    The exact error I get is:
    Error validating XML against schemacvc-elt.1: Cannot find the declaration of element rootNode

    where rootNode is the rootNode of my document. I even changed my schema file to not have any constraints and it still complains with the same error.

    Java Code:
    File schema = new File(xsdLocation);
    Document xmlDoc = getXMLDocument(xmlFile);
     SchemaFactory factory =
     Schema schema = factory.newSchema(schemaFile);
    Validator validator = schema.newValidator();
    DOMSource dom = new DOMSource(xmlDoc);

  2. #2
    devin is offline Member
    Join Date
    Feb 2009
    Rep Power


    Solved this one. Had a namespace issue. Just changed my XSD to only have this at the top:

Similar Threads

  1. XML Schema what is it good for.
    By kroiz in forum XML
    Replies: 4
    Last Post: 08-20-2009, 05:30 AM
  2. xml schema to document convert?
    By makpandian in forum XML
    Replies: 4
    Last Post: 08-12-2009, 11:57 AM
  3. XML Schema
    By Abder-Rahman in forum XML
    Replies: 1
    Last Post: 02-22-2009, 05:33 PM
  4. Merge 2 XMLs Based on Schema
    By wowstartup in forum XML
    Replies: 0
    Last Post: 02-12-2009, 06:46 PM
  5. Graphic library for XML Schema
    By earns in forum XML
    Replies: 0
    Last Post: 10-26-2008, 05:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts