Xml validation with schema, unbounded and any order of elements

Hi
I want to validate a xml file the user creates. I am currently using schema to do this. However there needs to be the possibility of a totally random mix of three different types of elements in a parent element. I couldn't find out how to do this, maybe it is not possible with schema? I thought I could look at the error message generated and ignore it if it was caused by one of the three elements mentioned above, but while the error message generated says which element is expected, it does not say which element caused the error.
Thanks in advance for any help.

Ruskin wrote:
However there needs to be the possibility of a totally random mix of three different types of elements in a parent element. Can you take your example to make it more clear? Does all three elements mutually exclusive?

Similar Messages

  • Erro in XML validation with schema document.

    Hi Friends,
    I am trying to validate XML file as per the defined schema document through JAXB parser.
    Following is my xml. schema and java class code.
    XML File_
    <?xml version="1.0"?>
    <notify xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="NotificationDetailsSchema.xsd">
    <notification>
    <alertname>Alert1</alertname>
    <deletable>Y</deletable>
    <descurl>Alert1URL</descurl>
    </notification>
    <notification>
    <alertname>Alert2</alertname>
    <deletable>Y</deletable>
    <descurl>Alert2URL</descurl>
    </notification>
    </notify>
    Schema file_
    <?xml version="1.0" encoding="windows-1252"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xsd:element name="notify">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="notification" maxOccurs="unbounded">
    <xsd:complexType mixed="true">
    <xsd:sequence>
    <xsd:element name="alertname">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="1"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="deletable">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="Y|N"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="descurl">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="1"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    </xsd:schema>
    Java Class_
    SAXSource source = new SAXSource (xmlInputSource);
    SchemaFactory sf = SchemaFactory.newInstance (XMLConstants.W3C_XML_SCHEMA_NS_URI);
    Schema schema = sf.newSchema(schemaFileObj);
    Validator validator = schema.newValidator ();
    validator.setErrorHandler (new ParserErrorHandler());
    validator.validate (source);
    I tried to execute the validation through stand along java class and it worked correctly.
    However when I added this class into my Fusion web application, I am getting following error.
    org.xml.sax.SAXParseException: s4s-elt-character: Non-whitespace characters are not allowed in schema elements other than 'xs:appinfo' and 'xs:documentation'. Saw 'USAVER'.*
    Can you please help me to figure out this problem?

    Ruskin wrote:
    However there needs to be the possibility of a totally random mix of three different types of elements in a parent element. Can you take your example to make it more clear? Does all three elements mutually exclusive?

  • XML validation with XSD, Cannot find the declaration of element 'rules'

    i am able to validate xml with XSD, from windows env, but same is not doing with linux, it is throwing error Cannot find the declaration of element 'rules'
    code here is
    validate(String aFilePath, String aSchemaFilePath)
    final String JAXP_SCHEMA_LANGUAGE = "http://java.sun.com/xml/jaxp/properties/schemaLanguage";
              final String W3C_XML_SCHEMA = "http://www.w3.org/2001/XMLSchema";
              final String JAXP_SCHEMA_SOURCE = "http://java.sun.com/xml/jaxp/properties/schemaSource";
    if(lSchemaFilePath == null){
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
    factory.setAttribute(JAXP_SCHEMA_SOURCE, new File(aSchemaFilePath));
    factory.setNamespaceAware(true);
    factory.setValidating(true);
    DocumentBuilder builder = factory.newDocumentBuilder();
    mValidator = new ValidationHandler();
    builder.setErrorHandler(mValidator);
    lDocument = builder.parse(aFilePath);
    if(mValidator.mErrorExist){
              }Thanks
    vittal

    here's the sample gml file.
    <?xml version="1.0" encoding="UTF-8"?>
    <ksj:Dataset gml:id="C01_DataSet" xmlns:ksj="http://nlftp.mlit.go.jp/ksj/schemas/ksj-app" xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://nlftp.mlit.go.jp/ksj/schemas/ksj-app AppSchema-C01-v1_0.xsd">
         <gml:description>CO1 description</gml:description>
         <gml:boundedBy>
              <gml:EnvelopeWithTimePeriod srsName="JGD2000 / (B, L)" frame="GC / JST">
                   <gml:lowerCorner>24.03 122.93</gml:lowerCorner>
                   <gml:upperCorner>45.52 145.82</gml:upperCorner>
                   <gml:beginPosition calendarEraName="Seireki">1965</gml:beginPosition>
                   <gml:endPosition calendarEraName="Seireki">1990</gml:endPosition>
              </gml:EnvelopeWithTimePeriod>
         </gml:boundedBy>
         <gml:Point gml:id="pt_1">          
              <gml:pos>24.33741667 123.73177778</gml:pos>
         </gml:Point>
         <gml:Point gml:id="pt_2">
              <gml:pos>24.33158333 124.10552778</gml:pos>
         </gml:Point>
         <gml:Point gml:id="pt_3">
              <gml:pos>26.28205556 127.73950000</gml:pos>
         </gml:Point>
         <gml:Point gml:id="pt_4">
              <gml:pos>26.23777778 127.96491667</gml:pos>
         </gml:Point>
         <ksj:Tide gml:id="fi_1">
              <ksj:position xlink:href="#pt_1"/>
              <ksj:springTideRange>13</ksj:springTideRange>
              <ksj:neapRange>5</ksj:neapRange>
              <ksj:averageHighTideInterval>69</ksj:averageHighTideInterval>
         </ksj:Tide>
         <ksj:TidalCurrent gml:id="fi_2">
              <ksj:position xlink:href="#pt_2"/>
              <ksj:risingTideCurrent>
                   <ksj:TidalCurrentInfo>
                        <ksj:currentDirection>14</ksj:currentDirection>
                        <ksj:currentSpeed>3</ksj:currentSpeed>
                   </ksj:TidalCurrentInfo>
              </ksj:risingTideCurrent>
              <ksj:fallingTideCurrent>
                   <ksj:TidalCurrentInfo>
                        <ksj:currentDirection>6</ksj:currentDirection>
                        <ksj:currentSpeed>3</ksj:currentSpeed>
                   </ksj:TidalCurrentInfo>
              </ksj:fallingTideCurrent>
         </ksj:TidalCurrent>
         <ksj:Marina gml:id="fi_3">
              <ksj:position xlink:href="#pt_3"/>
              <ksj:name>Marinafi3</ksj:name>
              <ksj:facilityCode>4703</ksj:facilityCode>
              <ksj:administrativeAreaCode codeSpace="AdministrativeAreaCode.xml">47205</ksj:administrativeAreaCode>
              <ksj:establishmentYear>
                   <gml:TimeInstant gml:id="ti_3">
                        <gml:timePosition>1987</gml:timePosition>
                   </gml:TimeInstant>
              </ksj:establishmentYear>
              <ksj:administratorClass>1</ksj:administratorClass>
              <ksj:numberOfKeptShips>
                   <ksj:NumberOfKeptShips>
                        <ksj:max>263</ksj:max>
                        <ksj:now>83</ksj:now>
                   </ksj:NumberOfKeptShips>
              </ksj:numberOfKeptShips>
              <ksj:frequencyOfSailing>900</ksj:frequencyOfSailing>
              <ksj:facilitiesAbove>facilitiesAbove1</ksj:facilitiesAbove>
              <ksj:facilitiesAbove>facilitiesAbove2</ksj:facilitiesAbove>
              <ksj:facilitiesAbove>facilitiesAbove3</ksj:facilitiesAbove>
              <ksj:facilitiesAbove>facilitiesAbove4</ksj:facilitiesAbove>
         </ksj:Marina>
         <ksj:MarinePhenomenonObservationFacilities gml:id="fi_4">
              <ksj:position xlink:href="#pt_4"/>
              <ksj:name>MarineName</ksj:name>
              <ksj:facilityCode>47001</ksj:facilityCode>
              <ksj:administrativeAreaCode codeSpace="AdministrativeAreaCode.xml">47323</ksj:administrativeAreaCode>
              <ksj:establishmentYear>
                   <gml:TimeInstant gml:id="ti_4">
                        <gml:timePosition>1983</gml:timePosition>
                   </gml:TimeInstant>
              </ksj:establishmentYear>
              <ksj:administratorClass>7</ksj:administratorClass>
              <ksj:observationItem>observationItem1</ksj:observationItem>
              <ksj:observationItem>observationItem2</ksj:observationItem>
              <ksj:observationItem>observationItem3</ksj:observationItem>
              <ksj:observationItem>observationItem4</ksj:observationItem>
              <ksj:observationItem>observationItem5</ksj:observationItem>
              <ksj:observationItem>observationItemOthers</ksj:observationItem>
         </ksj:MarinePhenomenonObservationFacilities>
    </ksj:Dataset>

  • XML Validation with multiple XSD files (referenced)

    Hello,
    I know that XML validation with version 7.1 is possible now. However I was provided with a set of XSD files that have references to each other and need to be placed in a hierachical file system order so that references can be resolved.
    An element <xsl:include schemaLocation="../../baseSchemas/baseSchema.xsd" /> is used for example. How can I handle that for XSD validation in PI? Can I create the same folder structure or do I need to put all XSD files in one directory and change the import manually?
    But most important question: Is it possible it all to use more than one XSD for schema validation?

    Dear Florian,
    I had encountered such case in a project.
    I was given 3 files. One main file and 2 others called Schema1.xsd and Schema2.xsd.
    This happens because your data type is not in single namespace, but is being referred across namespaces and software components.
    I am assuming that you have read the How to Guide for XML validations on PI 7.1
    Best way to do this quickly is as follows.
    1. Enable XML validation at adapter engine in the sender agreement.
    2. Post a message using HTTP post. (http://sappihttpclient.codeplex.com)
    3. Check communication channel in runtime workbench. There will be an error saying which is missing at what path.
    4. Create the path mentioned and place the file at that path.
    5. Repeat steps 2,3,4 for all the files.
    When you are done with this, you will get a proper validation error in case XML file is not correct. And remember to generate XSD from message type and not data type.
    Regards,
    Vikas
    Edited by: Vikas Aggarwal on Sep 2, 2009 8:45 PM
    Edited by: Vikas Aggarwal on Sep 2, 2009 8:48 PM

  • Have an issue regarding library books. My ereader is validated with Kobo account and Adobe Digital Editions account, but I get an error: 'this document is protected bij DRM and isn't available with your Adobe ID'.

    Have an issue regarding library books. My ereader is validated with Kobo account and Adobe Digital Editions account, but I get an error: 'this document is protected bij DRM and isn't available with your Adobe ID'.

    same problem for me. I am using abe edition 3 as I don't think 4 can be used with kobo. Book has been downloaded to kobo but it can't be read as it is not authorised.Help please

  • SAX Parser Validation with Schemas (C, C++ and JAVA)

    We are currently using the Oracle XML Parser for C to parse and validate XML data using the SAX parser interface with validation turned on. We currently define our XML with a DTD, but would like to switch to schemas. However, the Oracle XML Parser 9.2.0.3.0 (C) only validates against a DTD, not a schema when using the SAX interface. Are there plans to add schema validation as an option? If so, when would this be available? Also, the same limitation appears to be true for C++ and JAVA. When will any of these provide SAX parsing with schema validation?
    Thanks!
    John

    Will get back to you after checked with development team...

  • Disable XML Validation  (with default table defined in schema)

    Hi,
    Is there a way to disable validations when an XML is put into a XMLType table?
    I have registered my XML as,
    vsql := 'BEGIN
    DBMS_XMLSCHEMA.registerSchema(
    SCHEMAURL => ''ETV_EPG.xsd'',
    SCHEMADOC => bfilename(''MYDIR'',''MY_XSD.xsd''),
    OWNER => ''EPGMANAGER'',
    CSID => nls_charset_id(''AL32UTF8'')
    END;';
    And my XSD has the following,
    <xs:element name="Data" type="ProgramGuide" xdb:defaultTable="MY_TAB" />
    which causes any XML file (which adheres to MY_XSD) which I FTP to Oracle be ingested to MY_TAB.
    However my XSD has several Key and Keyref elements which causes a lot of validations to take place and slows down the ingest. I want to skip those validations as I am confident that the XML conforms to the schema.
    Thanks in advance,
    Vishal

    user5837642 wrote:
    Hi,
    Is there a way to disable validations when an XML is put into a XMLType table?
    I have registered my XML as,
    vsql := 'BEGIN
    DBMS_XMLSCHEMA.registerSchema(
    SCHEMAURL => ''ETV_EPG.xsd'',
    SCHEMADOC => bfilename(''MYDIR'',''MY_XSD.xsd''),
    OWNER => ''EPGMANAGER'',
    CSID => nls_charset_id(''AL32UTF8'')
    END;';
    And my XSD has the following,
    <xs:element name="Data" type="ProgramGuide" xdb:defaultTable="MY_TAB" />
    which causes any XML file (which adheres to MY_XSD) which I FTP to Oracle be ingested to MY_TAB.
    However my XSD has several Key and Keyref elements which causes a lot of validations to take place and slows down the ingest. I want to skip those validations as I am confident that the XML conforms to the schema.
    Are you using Binary storage or Object relational storage? You may want to have a look at this section of the documentation to see if it helps. In particular, you may want to test if using setSchemaValidated() makes any difference.

  • 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

  • XML validation with JDOM / JAXP

    Hello,
    I am trying to validate xml file against schema file. I decided to use JDOM and JAXP.
    First question: is it a good choice?
    I did a first attempt but not sure I have understood all what I am doing :(
    First I have create a parser usinf org.jdom.*
    SAXBuilder parser = new SAXBuilderThen I built my document:
    Document doc = parser.build(myFile)These 2 steps are ok. But it does not do validation.
    I saw in the JDOM documentation that I can set a validation flag to true. I did it. First problem, I got the following error from JDOMException: Document is invalid: no grammar found.
    Is there a way to specify to the parser where to find the xsd file?
    As I did not find answer to this question by myself, I tried implementing the Schema class from JAXP:
    SAXBuilder parser = new SAXBuilder;
    Document doc = parser.build(myFile);
    Schema schema = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(schemaFile);
    ValidatorHandler vh = schema.newValidatorHandler();
    SAXOutputter so = new SAXOutputter(vh);
    so.output(doc);It does the validation against the schema file specified but I am not really sure about what I am doing here. The last 2 commands are not clear to me :(
    Then in my schema file, I have elements that have default value. I expected the following behavior: if the element is not in the xml file then the default will be used by the parser (and added in the tree). But it seems, it's not the case.
    Any help/explanation will be really appreciated.

    I am trying to validate xml file against schema file. I decided to use JDOM and JAXP.
    First question: is it a good choice?
    If only schema validation is required use the validation API in JDK 5.0.
    http://www-128.ibm.com/developerworks/xml/library/x-javaxmlvalidapi.html
    http://java.sun.com/developer/technicalArticles/xml/validationxpath/
    For validation with JDOM, the following validation application explains the procedure:import org.jdom.input.SAXBuilder;
    import org.xml.sax.SAXException;import org.jdom.*;
    import java.io.*;
    public class JDOMValidator{
    public void validateSchema(String SchemaUrl, String XmlDocumentUrl){
               try{
    SAXBuilder saxBuilder = new SAXBuilder("org.apache.xerces.parsers.SAXParser",true);<br/>saxBuilder.setValidation(true);
    saxBuilder.setFeature("http://apache.org/xml/features/validation/schema",true);
    saxBuilder.setFeature("http://apache.org/xml/features/validation/schema-full-checking",true);
    saxBuilder.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",SchemaUrl);
    Validator handler=new Validator();
    saxBuilder.setErrorHandler(handler);
    saxBuilder.build(XmlDocumentUrl);
    if(handler.validationError==true)
    System.out.println("XML Document has Error:"+handler.validationError+""+
    handler.saxParseException.getMessage());      
    else           
          System.out.println("XML Document is valid");
              }catch(JDOMException jde){
                }catch(IOException ioe){
    private class Validator extends DefaultHandler{     
         public boolean  validationError = false; 
         public SAXParseException saxParseException=null;    
      public void error(SAXParseException exception) throws SAXException{        
         validationError =true;
         saxParseException=exception; 
      public void fatalError(SAXParseException exception) throws SAXException  {
    validationError = true;     
    saxParseException=exception;
      public void warning(SAXParseException exception) throws SAXException       {
    public static void main(String[] argv)   {
       String SchemaUrl=argv[0];StringXmlDocumentUrl=argv[1];
       JDOMValidator validator=new JDOMValidator();
       validator.validateSchema(SchemaUrl,XmlDocumentUrl);
    }

  • XML Validation with Sun Multischema XML Validator

    Dear readers,
    I am able to parse an XML file and validate it with a W3C-schema.
    But has anyone ever tried and succeeded in validating a part of an XML file or DOMDocument? It should go with the Sun MultiSchema Validator.
    Available @ http://wwws.sun.com/software/xml/developers/multischema/
    If anyone has a nice working example for validating a part of an XML-file it would certainly come in handy!
    I think it has something to do with that Acceptor interface...
    Any help is welcome.
    Regards
    Bram

    Solved the problem myself...
    Dukedollars are removed.
    You can use Sun multischema validator in combination with dom4j and
    manipulate your XML doc in memory. And also validate on Node level!

  • XML validation with StAX

    Hi,
    I have a requirement to validate XMLs during JAXB unmarshalling and during StAX parsing. The schema is packaged in a jar. I am able to successfully read the schema, and validate the XML during unmarshalling by setting the schema in the unmarshaller (through setSchema()).
    However, I am not able to validate it with StAX using the same schema and same XML.
    Here is the code snippet for StAX:
    StringReader stringReader = new StringReader(inputXMLStr);
    XMLEventReader xmlEventReader = XMLInputFactory.newInstance().createXMLEventReader(stringReader);
    EventFilter filter = new EventFilter() {
    public boolean accept(XMLEvent event) {
    return event.isStartElement();
    XMLEventReader xmlFilteredEventReader = xmlif.createFilteredReader(xmlEventReader, filter);
    Schema mySchema = getSchema(); // this method retrieves the schema by reading the schema files as
    stream source and calling schemaFactory.newSchema(...)
    Validator validator = mySchema.newValidator();
    validator.setErrorHandler(new SchemaErrorHandler());
    Source xmlSource = new StAXSource(xmlFilteredEventReader);
    validator.validate(xmlSource);
    I get a SAX Parse exception saying "cvc-elt.1: Cannot find the declaration of element 'myElement'"
    And I also see the following exception:
    Caused by: java.lang.NullPointerException
         at com.sun.org.apache.xalan.internal.xsltc.trax.StAXEvent2SAX.bridge(StAXEvent2SAX.java:171)
         at com.sun.org.apache.xalan.internal.xsltc.trax.StAXEvent2SAX.parse(StAXEvent2SAX.java:118)
         at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transformIdentity(TransformerImpl.java:651)
         at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:708)
         at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerImpl.transform(TransformerImpl.java:313)
         at com.sun.org.apache.xerces.internal.jaxp.validation.StAXValidatorHelper.validate(StAXValidatorHelper.java:89)
         at com.sun.org.apache.xerces.internal.jaxp.validation.ValidatorImpl.validate(ValidatorImpl.java:114)
         at javax.xml.validation.Validator.validate(Validator.java:127)
    I am not able to figure out why the validation would work with UnMarshaller but not with StAX.
    Any help appreciated.
    Thanks
    Meera

    Have u tried the Stream STAX parser instead?
    something like:
    SchemaFactory factory = SchemaFactory
                             .newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
    File schemaLocation = new File(XSD_FILE_PATH);
                   Schema schema = factory.newSchema(schemaLocation);
    // 3. Get a validator from the schema.
    Validator validator = schema.newValidator();
    ErrorHandler lenient = new ForgivingErrorHandler(fw);
    validator.setErrorHandler(lenient);
    XMLInputFactory staxFactory = XMLInputFactory.newInstance();
    staxFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES,
                             Boolean.TRUE);
    staxFactory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES,
                             Boolean.FALSE);
    staxFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE,
                             Boolean.TRUE);
    staxFactory     .setProperty(XMLInputFactory.IS_COALESCING, Boolean.TRUE);
    FileInputStream fis = new FileInputStream(XML_FILE_PATH);
    XMLStreamReader xmlr = staxFactory.createXMLStreamReader(fis);
    validator.validate(new StAXSource(xmlr));

  • XML Validation with no connection to the internet

    Hi,
    I'm trying to validate a ml instance document against a xml schema, using the javax.xml.validation.Validator.validate() method. This works fine as long as I have an internet connection, but not when I disconnect from the internet it fails.
    I've detected, using a network sniffer, that this is due to the fact that the validation process tries to fetch the XMLSchema.dtd and datatypes.dtd from w3.org. Is there any way to avoid this by prestoring these somewhere? So that the internet connection is not needed?
    I need to be able to do validation without a connection to the internet since the environment where my application is deployed does not have such a connection.
    Ray

    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 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 Validation with Java

    I have created a XML file with dom4j and the file confirmed to be valid when I read the file with Internet Explorer, a online XML validator and a free XML editor called "CookTop". However, when I attemp to read the XML file during the execution of an ant task I always get the XML parsing exception that one of my tag is not closed. I have even wrapped that test inside the tag as CDATA but that does not help as well. Do any one know what's happening? Here's my environment:
    JDK: 1.4.2_05
    Xerces: 2.6.2
    Ant: 1.5.3
    Thanks so much in advance.
    I've been pumping my head into the wall for hours : p

    Can i know where to download the CookTop?or CookTop2?

  • 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

Maybe you are looking for

  • PrintWriter question- is it possible to print out a table?

    Hi everyone, I am taking the information retrieved from a database and printing it out to a text file using FileOutputStream and PrintWriter. My question is can i format the printout in any way-- like print out certain records in some sort of table,

  • Cropped Photos Not Viewable (iPhoto 6.06)

    When I open iPhoto, I can see all of the photo thumbnails. My titles and ratings are still displayed. When I double-click on any photo that has been cropped or otherwise edited, the photo will appear in the Edit Window for a split second, then a larg

  • Front Row Gone Wild?

    Hello! It seems as if Front Row occasionally likes to go nuts and take up 99% of my CPU and exponentially increasing amounts of memory at random intervals. This happens only when I'm not using Front Row and just using my computer regularly. As far as

  • PE7 very slow Windows 7 64 bit

    Hi guys, PE7 is running very slowly for me. I'm running an i7 920 with 8GB of ram. Windows 7 64 bit Graphics card is Nvidia GeForce 9600GT running the latest driver V270.61 I am importing AVCHD videos into PE7 and then just dragging them across onto

  • Could someone explain me about tools like "RICEF"

    Hi Guys, Could someone explain me about tools like "RICEF"(I dont know if iam spelling it correctly) and ASAP methodology. Iam wondering how this are related to SAP upgrade and fresh SAP implementation. Many thanks in advance. Warm Regards, Garrick.