In-memonry xml document validation against schema with xerces

Hello, there.
I found that I can't use JAXP's javax.xml.validation package with jdk 1.4. (Am I wrong?)
Anyway,
I found that I can use xerces's DOMParser for the same purpose.
But I can't find the way to validate my programmatically generate org.w3c.dom.Document against existing schema file.
Can anybody help me?
Thanks.

Have you read Xerces documentation or SUN xml API, there is always a parser option (I suppose it's in the standard) to validate input while parsing.
Look the API : http://java.sun.com/javase/6/docs/api/javax/xml/parsers/DocumentBuilderFactory.html#setValidating(boolean)

Similar Messages

  • Xml document validation using Schema

    I want to validate XML Document using XML Schema...
    does any body have an idea how to do it.
    Every time i m running my java file by using different XML FILE AND XSD FILE in command line i m getting same error.
    error is:
    Exception in thread "main" org.xml.sax.SAXException: Error: URI=null Line=2: s4s-elt-schema-ns: The namespace of element 'catalog' must be from the schema name space.
    at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1115)
    at SAXLocalNameCount.main(SAXLocalNameCount.java:117)
    Below is my java code with xml file and schema file.
    plz get back to me as soon as possible it is urgent.
    thanx
    java File
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.*;
    import java.util.*;
    import java.io.*;
    public class SAXLocalNameCount extends DefaultHandler {
    /** Constants used for JAXP 1.2 */
    static final String JAXP_SCHEMA_LANGUAGE =
    "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
    static final String W3C_XML_SCHEMA =
    "http://www.w3.org/2001/XMLSchema";
    static final String JAXP_SCHEMA_SOURCE =
    "http://java.sun.com/xml/jaxp/properties/schemaSource";
    /** A Hashtable with tag names as keys and Integers as values */
    private Hashtable tags;
    // Parser calls this once at the beginning of a document
    public void startDocument() throws SAXException {
    tags = new Hashtable();
    // Parser calls this for each element in a document
    public void startElement(String namespaceURI, String localName,
    String qName, Attributes atts)
         throws SAXException
    String key = localName;
    Object value = tags.get(key);
    if (value == null) {
    // Add a new entry
    tags.put(key, new Integer(1));
    } else {
    // Get the current count and increment it
    int count = ((Integer)value).intValue();
    count++;
    tags.put(key, new Integer(count));
    System.out.println("TOTAL NUMBER OF TAG IN FILE = "+count);
    // Parser calls this once after parsing a document
    public void endDocument() throws SAXException {
    Enumeration e = tags.keys();
    while (e.hasMoreElements()) {
    String tag = (String)e.nextElement();
    int count = ((Integer)tags.get(tag)).intValue();
    System.out.println("Local Name \"" + tag + "\" occurs " + count
    + " times");
    static public void main(String[] args) throws Exception {
    String filename = null;
    String schemaSource = null;
    // Parse arguments
    schemaSource = args[0];
    filename = args[1];
    // Create a JAXP SAXParserFactory and configure it
    SAXParserFactory spf = SAXParserFactory.newInstance();
    // Set namespaceAware to true to get a parser that corresponds to
    // the default SAX2 namespace feature setting. This is necessary
    // because the default value from JAXP 1.0 was defined to be false.
    //spf.setNamespaceAware(true);
    // Validation part 1: set whether validation is on
    spf.setValidating(true);
    // Create a JAXP SAXParser
    SAXParser saxParser = spf.newSAXParser();
    System.out.println(" saxparser "+saxParser);
    // Validation part 2a: set the schema language if necessary
    if (true) {
    try {
    saxParser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
    System.out.println(" saxparser ");
    } catch (SAXNotRecognizedException x) {
    // This can happen if the parser does not support JAXP 1.2
    System.err.println(
    "Error: JAXP SAXParser property not recognized: "
    + JAXP_SCHEMA_LANGUAGE);
    System.err.println(
    "Check to see if parser conforms to JAXP 1.2 spec.");
    System.exit(1);
    // Validation part 2b: Set the schema source, if any. See the JAXP
    // 1.2 maintenance update specification for more complex usages of
    // this feature.
    if (schemaSource != null) {
    saxParser.setProperty(JAXP_SCHEMA_SOURCE, new File(schemaSource));
    System.out.println(" saxparser 123");
    // Get the encapsulated SAX XMLReader
    XMLReader xmlReader = saxParser.getXMLReader();
    System.out.println(" XML READER "+xmlReader);
    // Set the ContentHandler of the XMLReader
    xmlReader.setContentHandler(new SAXLocalNameCount());
    System.out.println(" XML READER 345 ");
    // Set an ErrorHandler before parsing
    xmlReader.setErrorHandler(new MyErrorHandler(System.err));
    System.out.println(" XML READER 67878 ");
    // Tell the XMLReader to parse the XML document
    xmlReader.parse(filename);
    System.out.println(" XML READER ");
    // Error handler to report errors and warnings
    private static class MyErrorHandler implements ErrorHandler {
    /** Error handler output goes here */
    private PrintStream out;
    MyErrorHandler(PrintStream out) {
    this.out = out;
    * Returns a string describing parse exception details
    private String getParseExceptionInfo(SAXParseException spe) {
    String systemId = spe.getSystemId();
    if (systemId == null) {
    systemId = "null";
    String info = "URI=" + systemId +
    " Line=" + spe.getLineNumber() +
    ": " + spe.getMessage();
    return info;
    // The following methods are standard SAX ErrorHandler methods.
    // See SAX documentation for more info.
    public void warning(SAXParseException spe) throws SAXException {
    out.println("Warning: " + getParseExceptionInfo(spe));
    public void error(SAXParseException spe) throws SAXException {
    String message = "Error: " + getParseExceptionInfo(spe);
    throw new SAXException(message);
    public void fatalError(SAXParseException spe) throws SAXException {
    String message = "Fatal Error: " + getParseExceptionInfo(spe);
    throw new SAXException(message);
    xml file(books.xml)
    <?xml version="1.0"?>
    <catalog>
    <book id="bk101">
    <author>Gambardella, Matthew</author>
    <title>XML Developer's Guide</title>
    <genre>Computer</genre>
    <price>44.95</price>
    <publish_date>2000-10-01</publish_date>
    <description>An in-depth look at creating applications
    with XML.</description>
    </book>
    <book id="bk102">
    <author>Ralls, Kim</author>
    <title>Midnight Rain</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2000-12-16</publish_date>
    <description>A former architect battles corporate zombies,
    an evil sorceress, and her own childhood to become queen
    of the world.</description>
    </book>
    <book id="bk103">
    <author>Corets, Eva</author>
    <title>Maeve Ascendant</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2000-11-17</publish_date>
    <description>After the collapse of a nanotechnology
    society in England, the young survivors lay the
    foundation for a new society.</description>
    </book>
    <book id="bk104">
    <author>Corets, Eva</author>
    <title>Oberon's Legacy</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2001-03-10</publish_date>
    <description>In post-apocalypse England, the mysterious
    agent known only as Oberon helps to create a new life
    for the inhabitants of London. Sequel to Maeve
    Ascendant.</description>
    </book>
    <book id="bk105">
    <author>Corets, Eva</author>
    <title>The Sundered Grail</title>
    <genre>Fantasy</genre>
    <price>5.95</price>
    <publish_date>2001-09-10</publish_date>
    <description>The two daughters of Maeve, half-sisters,
    battle one another for control of England. Sequel to
    Oberon's Legacy.</description>
    </book>
    <book id="bk106">
    <author>Randall, Cynthia</author>
    <title>Lover Birds</title>
    <genre>Romance</genre>
    <price>4.95</price>
    <publish_date>2000-09-02</publish_date>
    <description>When Carla meets Paul at an ornithology
    conference, tempers fly as feathers get ruffled.</description>
    </book>
    <book id="bk107">
    <author>Thurman, Paula</author>
    <title>Splish Splash</title>
    <genre>Romance</genre>
    <price>4.95</price>
    <publish_date>2000-11-02</publish_date>
    <description>A deep sea diver finds true love twenty
    thousand leagues beneath the sea.</description>
    </book>
    <book id="bk108">
    <author>Knorr, Stefan</author>
    <title>Creepy Crawlies</title>
    <genre>Horror</genre>
    <price>4.95</price>
    <publish_date>2000-12-06</publish_date>
    <description>An anthology of horror stories about roaches,
    centipedes, scorpions and other insects.</description>
    </book>
    <book id="bk109">
    <author>Kress, Peter</author>
    <title>Paradox Lost</title>
    <genre>Science Fiction</genre>
    <price>6.95</price>
    <publish_date>2000-11-02</publish_date>
    <description>After an inadvertant trip through a Heisenberg
    Uncertainty Device, James Salway discovers the problems
    of being quantum.</description>
    </book>
    <book id="bk110">
    <author>O'Brien, Tim</author>
    <title>Microsoft .NET: The Programming Bible</title>
    <genre>Computer</genre>
    <price>36.95</price>
    <publish_date>2000-12-09</publish_date>
    <description>Microsoft's .NET initiative is explored in
    detail in this deep programmer's reference.</description>
    </book>
    <book id="bk111">
    <author>O'Brien, Tim</author>
    <title>MSXML3: A Comprehensive Guide</title>
    <genre>Computer</genre>
    <price>36.95</price>
    <publish_date>2000-12-01</publish_date>
    <description>The Microsoft MSXML3 parser is covered in
    detail, with attention to XML DOM interfaces, XSLT processing,
    SAX and more.</description>
    </book>
    <book id="bk112">
    <author>Galos, Mike</author>
    <title>Visual Studio 7: A Comprehensive Guide</title>
    <genre>Computer</genre>
    <price>49.95</price>
    <publish_date>2001-04-16</publish_date>
    <description>Microsoft Visual Studio 7 is explored in depth,
    looking at how Visual Basic, Visual C++, C#, and ASP+ are
    integrated into a comprehensive development
    environment.</description>
    </book>
    </catalog>
    (books.xsd)
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <xsd:element name="catalog">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="book" minOccurs="0" maxOccurs="unbounded">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="author" type="xsd:string"/>
    <xsd:element name="title" type="xsd:string"/>
    <xsd:element name="genre" type="xsd:string"/>
    <xsd:element name="price" type="xsd:float"/>
    <xsd:element name="publish_date" type="xsd:date"/>
    <xsd:element name="description" type="xsd:string"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:string"/>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>

    Add xmlns:xsi attribute to the root element <catalog>.
    <catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation='books.xsd'>

  • Validating a XMLdoc against schema with multiply namespaces

    Does anybody know how to validate xmldoc against schema with multiply namespaces?
    I'd appreciate any advice on how I should perform this operation.
    I used an example from OTN "Building Server-Side XML Schema Validation" which works fine
    for single xml-xsd validation only.
    I use 8.1.7.4 oracle version with XML SDK installed.
    The error I am getting is
    0RA-29532: Java call terminated by uncaught Java exception: oracle.xml.parser.schema.XSDException: no protocol: NAME1.xsd
    ORA-06512: at sys.schemavalidation, line 0
    Here is an example of my xsd:
    <?xml version="1.0"?>
    <xs:schema
    xmlns:name1="http://.../name1"
    xmlns:name2="http://.../name2"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="unqualified" attributeFormDefault="unqualified" version="1.1">
    <xs:import namespace="http://.../name1" schemaLocation="name1.xsd"/>
    <xs:import namespace="http://.../name2" schemaLocation="name2.xsd"/>
    <xs:element name="Header">
         <xs:complexType>
              <xs:sequence>
                   <xs:element name="ID" type="name1:IDType">
                   </xs:element>
                   <xs:element name="Code" type="name2:CodeType">
                   </xs:element>
              </xs:sequence>
         </xs:complexType>
    </xs:element>

    In the past, ColdFusion's XML validation mechanism seems to have had issues with schemas that contain imports, e.g., http://forums.adobe.com/message/155906. Have these issues still not been resolved?
    Do you not think that perhaps you're answering your own question here?
    I don't see an issue about this on the bug tracker.  It might be an idea if you can get a simple, stand-alone repro case together and raise an issue (and post the reference back here and against that other thread so people know to vote for it).  If you post the repro case here too, it would be helpful.
    Adam

  • Validating an XML document to a schema using ColdFusion

    This is something I have never tried before.  We created an XML Schema  to define XML documents we expect to receive from various entities.   When we receive the document, we would like to validate it before  processing it.  I think ColdFusion is up to this from reading the  documentation, but we have not got anything working yet.
    When we try and xmlParse() our test XML file against the XML schema we  get the following error.  When we use a web based XML validation tool  and feed it the same XML file and schema it validates just fine.
    An error occured while parsing an XML document.
    [Error] :2:6: cvc-elt.1: Cannot find the declaration of element 'pur'.
    The error occurred in D:\playground\warren\ppur_file_import.cfm: line 57
    55 :
    56 :
    57 : <cfset xmldoc = XmlParse(ExpandPath(filepath), true,  ExpandPath(validator)) />
    58 : <cfdump var="#xmldoc#">
    59 : <cfabort>
    Searching for the error has not provided me any useful hints.  Can  anybody here?

    XML SCHEMA
    <?xml version="1.0" encoding="iso-8859-1"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
         <!-- Simple Types -->
         <xs:simpleType name="RECORD_ID">
              <xs:restriction base="xs:string">
                   <xs:pattern value="[AaBbCc]"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="REPORT_MONTH">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="(0[1-9]|1[0-2])"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="REPORT_YEAR">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{2}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="MFG_FIRMNO">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{7}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="LABEL_SEQ_NO">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{5}"/>
              </xs:restriction>
         </xs:simpleType>     
         <xs:simpleType name="REVISION_NO">
              <xs:restriction base="xs:string">
                   <xs:pattern value="[A-Za-z]{2}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="REG_FIRMNO">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{7}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="GROWER_ID">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{11}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="CEDTS_IND">
              <xs:restriction base="xs:string">
                   <xs:pattern value="[Ee]|[ ]"/>
                   <!-- needs to match E or a blank. -->
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="APPLIC_DT">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="(0[1-9]|1[0-2])(0[1-9]|[1-2][0-9]|3[0-1])([0-9]{2})"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="SITE_CODE">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{6}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="QUALIFY_CD">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{2}"/>
              </xs:restriction>
         </xs:simpleType>     
         <xs:simpleType name="PLANTING_SEQ">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="ACRE_TREATED">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{8}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="UNIT_TREATED">
              <xs:restriction base="xs:string">
                   <xs:pattern value="[ATSCKUPatsckup]"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="AMT_PRD_USED">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{10}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="UNIT_OF_MEAS">
              <xs:restriction base="xs:string">
                   <xs:pattern value="LB|OZ|GA|QT|PT|KG|GR|LI|ML"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="DOCUMENT_NO">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{8}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="LINE_ITEM">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{4}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="PROCESS_DT">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{4}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="BATCH_NO">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-5][0-9][0-9][0-9]"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="COUNTY_CD">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-5][0-9]"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="SECTION">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{2}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="TOWNSHIP">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{2}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="TSHIP_DIR">
              <xs:restriction base="xs:string">
                   <xs:pattern value="[NSns]"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="RANGE">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{2}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="RANGE_DIR">
              <xs:restriction base="xs:string">
                   <xs:pattern value="[EWew]"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="BASE_LN_MER">
              <xs:restriction base="xs:string">
                   <xs:pattern value="[HMShms]"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="AER_GND_IND">
              <xs:restriction base="xs:string">
                   <xs:pattern value="[AFGOafgo]"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="SITE_LOC_ID">
              <xs:restriction base="xs:string">
                   <xs:pattern value="[-0-9 ]+"/>
                   <!-- Examples in files I checked
                         only had numeric characters and
                         a dash. The county contract doesn't
                         specify numeric-only, so letters may
                         be acceptable. I find no evidence of
                         any letters being used. -->
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="ACRE_PLANTED">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{8}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="UNIT_PLANTED">
              <xs:restriction base="xs:string">
                   <xs:pattern value="[ATSCKUPatsckup]"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="APPLIC_TM">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{4}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="APPLIC_CNT">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{6}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="FUME_CD">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[0-9]{4}"/>
              </xs:restriction>
         </xs:simpleType>
         <xs:simpleType name="LICENSE_NO">
              <xs:restriction base="xs:integer">
                   <xs:pattern value="[-0-9A-Za-z]{13}"/>
              </xs:restriction>
         </xs:simpleType>
         <!-- end Simple Types -->
         <!-- !!!!!!!!! Begin Abstract Types !!!!!!!!! -->
         <xs:complexType name="application_data_abs" abstract="true">
              <xs:sequence>          
                   <xs:element name="GROWER_ID" type="GROWER_ID" />                    
                   <xs:element name="CEDTS_IND" type="CEDTS_IND" />
                   <xs:element name="APPLIC_DT" type="APPLIC_DT" />     
                   <xs:element name="SITE_CODE" type="SITE_CODE" />               
                   <xs:element name="QUALIFY_CD" type="QUALIFY_CD" />
                   <xs:element name="PLANTING_SEQ" type="PLANTING_SEQ" />
                   <xs:element name="ACRE_TREATED" type="ACRE_TREATED" />                         
                   <xs:element name="UNIT_TREATED" type="UNIT_TREATED" />
                   <xs:element name="AMT_PRD_USED" type="AMT_PRD_USED" />
                   <xs:element name="UNIT_OF_MEAS" type="UNIT_OF_MEAS" />               
                   <xs:element name="DOCUMENT_NO" type="DOCUMENT_NO" />                         
                   <xs:element name="LINE_ITEM" type="LINE_ITEM" />
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="application_abs" abstract="true">
              <xs:sequence>
                   <xs:element name="key_data" type="key_data" />
                   <xs:element name="product_data" type="product_data" />
              </xs:sequence>
         </xs:complexType>
         <!-- !!!!!!!!! End Abstract Types !!!!!!!!! -->
         <!-- !!!!!!!!! Start Complex Types !!!!!!!!! -->
         <xs:complexType name="product_data">
              <xs:sequence>
                   <xs:element name="MFG_FIRMNO" type="MFG_FIRMNO" />               
                   <xs:element name="LABEL_SEQ_NO" type="LABEL_SEQ_NO"/>                         
                   <xs:element name="REVISION_NO" type="REVISION_NO" />
                   <xs:element name="REG_FIRMNO" type="REG_FIRMNO" />               
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="key_data">
              <xs:sequence>
                   <xs:element name="RECORD_ID" type="RECORD_ID" />     
                   <xs:element name="COUNTY_KEY">
                        <!--
                             The optional COUNTY_ID field would be used by
                             the Counties to include their internal
                             record identifier. This would allow DPR
                             to reference a county's internal record ID
                             in the event of data inconsistencies.
                        -->
                   </xs:element>
                   <xs:element name="REPORT_MONTH" type="REPORT_MONTH" />
                   <xs:element name="REPORT_YEAR" type="REPORT_YEAR" />
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="fileInfo">
              <xs:sequence>
                   <xs:element name="PROCESS_DT" type="PROCESS_DT" />                              
                   <xs:element name="BATCH_NO" type="BATCH_NO" />
                   <xs:element name="COUNTY_CD" type="COUNTY_CD" />
              </xs:sequence>
         </xs:complexType>     
         <xs:complexType name="mtrs_data">
              <xs:sequence>
                   <xs:element name="SECTION" type="SECTION" />
                   <xs:element name="TOWNSHIP" type="TOWNSHIP" />                                        
                   <xs:element name="TSHIP_DIR" type="TSHIP_DIR" />
                   <xs:element name="RANGE" type="RANGE" />
                   <xs:element name="RANGE_DIR" type="RANGE_DIR" />
                   <xs:element name="BASE_LN_MER" type="BASE_LN_MER" />
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="ag_application_data">
              <xs:complexContent>
                   <xs:extension base="application_data_abs">
                        <xs:sequence>                                             
                             <xs:element name="AER_GND_IND" type="AER_GND_IND" />
                             <xs:element name="SITE_LOC_ID" type="SITE_LOC_ID" />
                             <xs:element name="ACRE_PLANTED" type="ACRE_PLANTED" />
                             <xs:element name="UNIT_PLANTED" type="UNIT_PLANTED" />
                             <xs:element name="APPLIC_TM" type="APPLIC_TM" />
                             <xs:element name="FUME_CD" type="FUME_CD" />
                        </xs:sequence>
                   </xs:extension>
              </xs:complexContent>
         </xs:complexType>
         <xs:complexType name="nonag_application_data">
              <xs:complexContent>
                   <xs:extension base="application_data_abs">
                        <xs:sequence>                                        
                             <xs:element name="APPLIC_CNT" type="APPLIC_CNT" />
                             <xs:element name="LICENSE_NO" type="LICENSE_NO" />
                        </xs:sequence>
                   </xs:extension>
              </xs:complexContent>
         </xs:complexType>
         <!--- "Ag" -->
         <!--
              Type A:
              Data that would appear on individual lines
              in the old A type
              (F file type, agricultural job report)
              Type B:
              Data that would appear on individual lines
              in the old B type
              (F file type, agricultural monthly production summary)
         -->     
         <xs:complexType name="ag_application">
              <xs:complexContent>
                   <xs:extension base="application_abs">
                        <xs:sequence>                                        
                             <xs:element name="mtrs_data" type="mtrs_data" />
                             <xs:element name="application_data" type="ag_application_data" />
                        </xs:sequence>
                   </xs:extension>
              </xs:complexContent>
         </xs:complexType>
         <!--- "Non_Ag" -->     
         <!--
              Data that would appear on individual lines
              in the old C type
              (C file type, non-agricultural monthly summary)
         -->          
         <xs:complexType name="nonag_application">
              <xs:complexContent>
                   <xs:extension base="application_abs">
                        <xs:sequence>                                        
                             <xs:element name="application_data" type="nonag_application_data" />
                        </xs:sequence>
                   </xs:extension>
              </xs:complexContent>
         </xs:complexType>
         <!-- The individual lines of data that are transmitted. -->
         <xs:complexType name="data_lines">
              <xs:sequence>                                        
                   <xs:element name="Non_Ag" type="nonag_application" minOccurs="0" maxOccurs="unbounded"/>
                   <xs:element name="Ag" type="ag_application" minOccurs="0" maxOccurs="unbounded"/>                    
              </xs:sequence>
         </xs:complexType>
         <!-- !!!!!!!!! End Complex Types !!!!!!!!! -->
         <xs:element name="pur">     
              <xs:complexType>
                   <xs:sequence>               
                        <xs:element name="County" minOccurs="0" maxOccurs="1">
                             <!--
                                  Tag for counties to put county-specific
                                  data in (eg, their batch number, timestamp,
                                  contact info, etc)
                             -->
                        </xs:element>
                        <!-- File: information specific to the file -->               
                        <xs:element name="File" type="fileInfo" minOccurs="1" maxOccurs="1"/>
                        <!-- Data: lines of data transmitted -->
                        <xs:element name="Data" type="data_lines" minOccurs="1" maxOccurs="1"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
    </xs:schema>

  • XML validation against schema (NOT DTD)

    Hi,
    I am fairly new at parsing XML documents, but I am trying to parse
    an XML document using the Xerces SAXParser.
    I can parse my xml document, no problems there, but I want to validate
    it against an xml schema file, without specifying the file in the xml document.
    How can I do this? If I set validating to true, it gives me errors about a DTD,
    but I don't have a DTD, I want to use a schema file.
    Can anybody help me, or give me a code example?
    THanks,
    Sven

    SAXParser parser = new SAXParser();
                 parser.setFeature("http://xml.org/sax/features/validation",
                          true);
                 parser.setFeature("http://apache.org/xml/features/validation/schema",
                          true);
                 parser.setFeature("http://apache.org/xml/features/validation/schema-full-checking",
                          true);

  • XML validation against schema in XSD format

    I have a requirement for validation of XML file against XML schema(XSD format). Using IXML liabrary I know how to validate XML file against schema in DTD format. But i am not getting how to do it against XSD. Is it possible using IXML liabrary? Also i wanted to know how to attach one XML or CSV file into another XML file using SAP ABAP.
    Please provide solution!!

    Hi Madhura,
    see here my comparison of the web version against the local file version on my Windows box (which is itself not the fastest): It makes a factor 16 in difference!
    C:\Temp\xsdvalidator>java XsdValidator madhu.xsd madhu.xml
    cvc-pattern-valid: Value 'provamail.it' is not facet-valid with respect to patte
    rn '[^@]+@[^.]+[.].+' for type 'EmailType'.
    NOK - Validation error
    Elapsed time: 16353 ms
    C:\Temp\xsdvalidator>java XsdValidator madhu_local.xsd madhu.xml
    cvc-pattern-valid: Value 'provamail.it' is not facet-valid with respect to patte
    rn '[^@]+@[^.]+[.].+' for type 'EmailType'.
    NOK - Validation error
    Elapsed time: 994 ms
    Obviously, the w3c.org domain that you specified as ressource location is very slow - and, as the FAQ shows, this delay is intentional!
    The W3C servers are slow to return DTDs. Is the delay intentional?
    Yes. Due to various software systems downloading DTDs from our site millions of times a day (despite the caching directives of our servers), we have started to serve DTDs and schema (DTD, XSD, ENT, MOD, etc.) from our site with an artificial delay. Our goals in doing so are to bring more attention to our ongoing issues with excessive DTD traffic, and to protect the stability and response time of the rest of our site. We recommend HTTP caching or catalog files to improve performance.
    --> They don't want to have requests to their site from productive servers all around the world.
    Regards,
    Rüdiger

  • XML instance validation against XML schema

    How can I get a reference on the error node object after
    validation against an XML schema ?
    Ex. :
    DOMParser domP = new DOMParser();
    domP.setXMLSchema(schemaDoc); // schemaDoc = ref. on an XMLSchema
    domP.setValidationMode(XMLParser.SCHEMA_VALIDATION);
    domP.parse(reader); // reader contains the XML instance data
    If an error occurred, I only get a message string. What I need is to get a reference on the node object which contains the error in order to retrieve its properties to the schema.
    I could then alert the user with a message such as :
    "Data xxx is not valid ; it must be comprised between yy and zz...".
    Did somebody solve this problem ? May I use the XMLError class to do this ?
    Thank you

    Hi Ray,
    Were you able to resolve this issue? I am encountering a very similar problem where I am not connected to the internet and it fails during the newSchema method on javax.xml.validation.SchemaFactory. I have attempted to implement the suggestions of ExtremeGardener and vidyut with no luck.
    Per ExtremeGardener's suggestion of replacing xmlns:xs="http://www.w3.org/2001/XMLSchema" with xmlns:xs="XMLSchema.xsd" and storing it locally, it gave me an error for trying to set the "xs" or "xsd" prefixes to anything other than "http://www.w3.org/2001/XMLSchema." I forget the exact error. I also tried to use my own prefix and it did not like that either.
    Per vidyut's suggestion of using a catalog resolver, I believe that I have tried that too (if I understand correctly). I created an LSResourceResolver and tied it to the SchemaFactory. I can invoke it for a namespace but that did not resolve the issue because it only invokes the resolver on an import, include, or redefine. I believe that it is trying to reach the internet due to the xmlns:xs="http://www.w3.org/2001/XMLSchema" attribute within the top-level schema element in the XSD and I know of no way to invoke it for that.
    I also created an ErrorHandler and tied it to the SchemaFactory. That shows me the errors and they are all related to the standard XML data types defined in XMLSchema.xsd. The errors that I am seeing are all of this form: "UndeclaredPrefix: Cannot resolve 'xs:string' as a QName: the prefix 'xs' is not declared."
    I am currently using the SchemaFactory in Java 1.5, but I am thinking about trying the Xerces SchemaFactory since they are not exactly the same implementation.
    Does anyone have any other suggestions? Any help you can provide would be greatly appreciated!
    Thanks,
    betzro1

  • XML validation against Schema

    Hi,
    We have SAP WebAS 6.20. Can someone help me understand how I can validate XML document against schema in ABAP.
    Thanks,
    Suman

    hi
    u can check the below links
    XML schema in ABAP
    Can i use XSD / XML in Abap Programs
    Regards,
    Naveen

  • Using java to fill in the blanks in an xml document via a schema

    Hi all
    What im trying to do is basically take an xml document and run it through a xml schema validator and then if the xsd has any default values to basically populate the original xml document with these default values
    e.g.
    <root>
    <name>dave</name>
    <name></name>
    </root>
    the schema would be something like
    <xs:element name="name" default="bobby">
    after schema validation i would want the document to be
    <root>
    <name>dave</name>
    <name>bobby</name>
    </root>
    is that something possible to do in java with any specific xml frameworks out there? if so can any one give me any pointers in the right direction?

    i assume by the lack of response this cannot be done then :(

  • Oracle XML Parser validation against XML Sxhema

    Hi,
    I am developing a program in C++ on Unix, that does parsing on an XML document. For parsing I am using "Oracle XML Parser" [using DOM API]. My question is, Can Oracle XML Parser validate xml document against an XML Schema file also? I have read in many tutorials that it can validate against DTD. Please clarify my question as early as possible?
    Regards,
    Raghuram.

    Hi Kulkarni,
    I think you are trying to retrieve the text of the parent element of book. For example if this is the xml element
    <bookdetails>
    <book>Harry Potter</book>
    <author>JK Rowling</author>
    <price>34.55</price>
    </book>
    </bookdetails>
    You must be trying to retrieving the text of bookdetails.
    Check XMLNode.getNodeName() to retrieve the name of the node.
    To get 'Harry Potter' as output you need to traverse till book and then use XMLNode.getText()
    You can check the 'getQuestions()' method in Survey Sample
    to know how to tranverse to any element of an XML using Java.
    The Survey Sample is located at
    http://otn.oracle.com/sample_code/tech/xml/survey/content.html
    Download the sample and unjar it. The location of Analyser.java is
    SurveySample\code\Survey\src\oracle\otnsamples\survey\business\Analyser.java
    Have a look at it.
    Regards,
    Anupama
    http://otn.oracle.com/sample_code/content.html

  • Inserting XML document into XDB fails with can't convert to OPAQUE

    Hi,
    When I try to insert a document using oracle 9.2.0.5 client software into a 9.2.0.5 database, with the following code:
    void insertDocument(String document) {
    XMLType xt = XMLType.createXML(connection, document);
    PreparedStatement ps = connection.prepareStatement("insert into xmldocuments values(?)");
    ps.setObject(1, xt);
    ps.executeUpdate();
    The setObject function always throws an exception (after a very long time) with:
    java.sql.SQLException: Fail to convert to internal representation: OPAQUE()
    This also fails when we use the InputStream and org.w3c.xml.Document variants.
    We use the OCI driver, otherwise we get errors retrieving the documents from XMLDB.
    What is going wrong here?

    David,
    If you search through the historical data in this list there are previous post regarding opaque.
    These may be useful. Possibly your reaching the size limit.

  • How to map an large XML document to the XMLType with TopLink in JDev

    Hello!
    We need to map an XML document in the Java String to an XMLType column. If the XML document has less than 4000 characters, we have no problems by using the DirectToField mapping. However, once the XML document has more than 4000 characters, using the DirectToField mapping, we got the error: Exception [TOPLINK-4002] (Oracle TopLink - 10g Release 3 (10.1.3.0.0) (Build 060118)): oracle.toplink.exceptions.DatabaseException
    Internal Exception: java.sql.BatchUpdateException: ORA-01461: can bind a LONG value only for insert into a LONG column
    Then we have tried to use the "Type Conversion" mapping, to map it to the database type (Clob or NClob --oracle.toplink.oraclespecific). we got:
    Exception [TOPLINK-4002] (Oracle TopLink - 10g Release 3 (10.1.3.0.0) (Build 060118)): oracle.toplink.exceptions.DatabaseException
    Internal Exception: java.sql.SQLException: ORA-00932: inconsistent datatypes: expected NUMBER got CLOB
    Error Code: 932
    Any suggestions?
    Thanks in advance!

    Thanks Matt! It works fine by using DirectToXMLTypeMapping.
    However, to get it work is not smooth. In particularly, we use Jdev in our project and Jdev has not included this feature yet. Therefore, I had to use the TopLink Workbench to create the descriptor file and cut&paste to the description file that generated by JDev. And also xdb.jar has to be part of the classpath.
    Then I come to an question -- how can we take some features that only provided by the TopLink Workbench into the Jdev environment without having to hack around?
    Thanks,
    s.c.

  • Problem in xml validation against schema

    this is the xml file
    <?xml version="1.0" encoding="UTF-8"?><hello xmlns=""><Capabilities xmlns=""><capability xmlns="">base</capability><capability xmlns="">writablerunning</capability><capability xmlns="">null</capability><username xmlns="">netconf</username><password xmlns="">netconf</password></Capabilities></hello>
    xsd file is
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="urn:com.tel.netconf.server"
    xmlns="urn:com.tel.netconf.server"
    elementFormDefault="qualified"
    attributeFormDefault="unqualified">
    <xs:element name="hello" type="helloType"/>
    <xs:element name="username" type="xs:string"/>
    <xs:element name="password" type="xs:string"/>
    <xs:element name="Capabilities" type="capabilitiesinfo"/>
    <xs:complexType name="capabilitiesinfo">
    <xs:sequence>
    <xs:element name="capability" type="xs:string" minOccurs="1" maxOccurs="unbounded"/>
    <xs:element ref="username"/>
    <xs:element ref="password"/>
    </xs:sequence>
    </xs:complexType>
    <xs:complexType name="helloType>
    <xs:sequence>
    <xs:element ref="Capabilities"/>
    </xs:sequence>
    </xs:complexType>
    </xs:schema>
    error msg is
    Error: Document is invalid: no grammar found.
    at line 2, column 7
    in entity file:///D:/NETCONF/axis-src-1_4/axis/netconf/com/tel/netconf/server/h
    ello1.xml
    Error: Document root element "hello", must match DOCTYPE root "null".
    at line 2, column 7 in entity file:///D:/NETCONF/axis-src-1_4/axis/netconf/com/tel/netconf/server/h
    ello1.xml
    org.xml.sax.SAXParseException: The value of attribute "name" associated with an
    element type "xs:complexType" must not contain the '<' character.
    plz kindly help me out

    Hi Madhura,
    see here my comparison of the web version against the local file version on my Windows box (which is itself not the fastest): It makes a factor 16 in difference!
    C:\Temp\xsdvalidator>java XsdValidator madhu.xsd madhu.xml
    cvc-pattern-valid: Value 'provamail.it' is not facet-valid with respect to patte
    rn '[^@]+@[^.]+[.].+' for type 'EmailType'.
    NOK - Validation error
    Elapsed time: 16353 ms
    C:\Temp\xsdvalidator>java XsdValidator madhu_local.xsd madhu.xml
    cvc-pattern-valid: Value 'provamail.it' is not facet-valid with respect to patte
    rn '[^@]+@[^.]+[.].+' for type 'EmailType'.
    NOK - Validation error
    Elapsed time: 994 ms
    Obviously, the w3c.org domain that you specified as ressource location is very slow - and, as the FAQ shows, this delay is intentional!
    The W3C servers are slow to return DTDs. Is the delay intentional?
    Yes. Due to various software systems downloading DTDs from our site millions of times a day (despite the caching directives of our servers), we have started to serve DTDs and schema (DTD, XSD, ENT, MOD, etc.) from our site with an artificial delay. Our goals in doing so are to bring more attention to our ongoing issues with excessive DTD traffic, and to protect the stability and response time of the rest of our site. We recommend HTTP caching or catalog files to improve performance.
    --> They don't want to have requests to their site from productive servers all around the world.
    Regards,
    Rüdiger

  • Question about XML validation against schema

    My question is probably a basic one about XML. I tried PurchaseOrder example from the book "J2EE Web Services" by Richard Monson-Haefel. A simplified version as followings -
    Address.xsd -
    <?xml version="1.0" encoding="UTF-8"?>
    <schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://xml.netbeans.org/schema/Address"
    xmlns:addr="http://xml.netbeans.org/schema/Address"
    elementFormDefault="qualified">
    <element name="address" type="addr:USAddress" />
    <complexType name="USAddress">
    <sequence>
    <element name="name" type="string" />
    <element name="street" type="string" />
    <element name="city" type="string" />
    <element name="state" type="string" />
    <element name="zip" type="string" />
    </sequence>
    </complexType>
    </schema>
    PurchaseOrder.xsd -
    <schema xmlns="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://xml.netbeans.org/schema/PurchaseOrder"
    xmlns:po="http://xml.netbeans.org/schema/PurchaseOrder"
    xmlns:ad="http://xml.netbeans.org/schema/Address"
    elementFormDefault="qualified">
    <import namespace="http://xml.netbeans.org/schema/Address" schemaLocation="Address.xsd" />
    <element name="purchaseOrder" type="po:PurchaseOrder" />
    <complexType name="PurchaseOrder">
    <sequence>
    <element name="accountName" type="string" />
    <element name="accountNumber" type="unsignedShort" />
    <element name="shipAddress" type="ad:USAddress" />
    <element name="total" type="float" />
    </sequence>
    <attribute name="orderDate" type="date" />
    </complexType>
    </schema>
    Then PurchaseOrder.xml is -
    <purchaseOrder orderDate="2007-12-12"
    xmlns='http://xml.netbeans.org/schema/PurchaseOrder'
    xmlns:addr="http://xml.netbeans.org/schema/Address"
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xsi:schemaLocation='http://xml.netbeans.org/schema/PurchaseOrder ../xsd/PurchaseOrder.xsd'>
    <accountName>Starwood</accountName>
    <accountNumber>220</accountNumber>
    <shipAddress>
    <name>Data Center</name>
    <street>1501 Washington St.</street>
    <city>Braintree</city>
    <state>MA</state>
    <zip>02148</zip>
    </shipAddress>
    <total>250</total>
    </purchaseOrder>
    Then I did a XML validation but have this error -
    cvc-complex-type.2.4.a: Invalid content was found starting with element 'name'. One of '{"http://xml.netbeans.org/schema/Address":name}' is expected. [19]
    It complains <name> tag in <shipAddrss> needs namespace of "http://xml.netbeans.org/schema/Address". Why?
    Is it possible to change XML so it does not need name space for elements inside <shipAddress>?
    Thanks

    Hi Madhura,
    see here my comparison of the web version against the local file version on my Windows box (which is itself not the fastest): It makes a factor 16 in difference!
    C:\Temp\xsdvalidator>java XsdValidator madhu.xsd madhu.xml
    cvc-pattern-valid: Value 'provamail.it' is not facet-valid with respect to patte
    rn '[^@]+@[^.]+[.].+' for type 'EmailType'.
    NOK - Validation error
    Elapsed time: 16353 ms
    C:\Temp\xsdvalidator>java XsdValidator madhu_local.xsd madhu.xml
    cvc-pattern-valid: Value 'provamail.it' is not facet-valid with respect to patte
    rn '[^@]+@[^.]+[.].+' for type 'EmailType'.
    NOK - Validation error
    Elapsed time: 994 ms
    Obviously, the w3c.org domain that you specified as ressource location is very slow - and, as the FAQ shows, this delay is intentional!
    The W3C servers are slow to return DTDs. Is the delay intentional?
    Yes. Due to various software systems downloading DTDs from our site millions of times a day (despite the caching directives of our servers), we have started to serve DTDs and schema (DTD, XSD, ENT, MOD, etc.) from our site with an artificial delay. Our goals in doing so are to bring more attention to our ongoing issues with excessive DTD traffic, and to protect the stability and response time of the rest of our site. We recommend HTTP caching or catalog files to improve performance.
    --> They don't want to have requests to their site from productive servers all around the world.
    Regards,
    Rüdiger

  • Validating against schema file for the output XML file

    Hi,
      I am using XSLT for mapping. The output message is generated according to the mappings but it is not validate aganist schema of target . I am using xsd file from external defination section as target. Can any body help me in this regard.
    Thanks,
    Mallikarjun.M

    hi,
    if you talk about the schema of a target message type
    than validation only works if you use graphical
    message mapping
    not with: xslt,java, abap
    Regards,
    michal
    <a href="/people/michal.krawczyk2/blog/2005/06/28/xipi-faq-frequently-asked-questions">XI FAQ - Frequently Asked Questions</a>

Maybe you are looking for

  • Discoverer Report Scheduling Permissions question

    Quick question, i have a report which runs fine for all users, however when scheduled for certain users the report fails to return data. The report uses a folder with a call to the GL_SECURITY_PKG in the SQL. I have removed this and the report appear

  • One function for multiple buttons?

    I have a county map on my timeline with a list of each county as buttons ( there is 88 counties). I want to highlight the county on the map when I click the county's name from a list. when I test this out, only the last one gets highlighted. I know I

  • ITunes Match - Greyed out songs when iTunes restarted

    I am using iTunes 12 (latest version) on a Macbook 2010 running Yosemite 10.10.1 I do not store any music locally, and access around 2000 songs in iTunes Match. When I turn on iTunes Match, all songs display fine in iTunes. The problem - When I quit

  • Can't Parse XHTML with XPATH

    I can't seem to parse a simple XHTML 1.1 document with XPATH. In the code below, the string xmlDoesntWork is taken directly from http://www.w3.org/TR/2001/REC-xhtml11-20010531/conformance.html. However, XPATH can't find the <title> element unless I r

  • Getting 0xc000000f error

    hi my lap top wont open getting 0xc000000f error tried loads of suggestions but nothing