XML validation in 11g using DTD

Hello
I'm using a DTD, stored in a database table to validate client information XML files; the problem is that i have an element, lets say A, that has an atribuite Type, and this element have two sub-elements, B and C, so the XML is something like:
<A Type ="99">
             <B>LETTER B </B>
             <C>LETTER C </C>
</A>When using 9i database, the DTD had the folowing elements do check this item :
<!ELEMENT A (B?, C?)>
<!ATTLIST A TYPE (1|2|3|4|99) #REQUIRED>
<!ELEMENT B (#PCDATA)>
<!ELEMENT C (#PCDATA)>But when I try to use the same DTD in Oracle 11G and the same file that is correctly verified in 9i, I get :
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00103: Warning: document structure does not match DTD
After a few tests, I've modified the element A declaration in the DTD to <!ELEMENT A ANY>, and the XML is verified without error.
But the definition of ANY says that : Elements declared with the category keyword ANY, can contain any combination of parsable data; and that isn't very good on this case.
Can you please help me, does anyone stumble on this situation if so is there any way to solve it?
Many thanks for any answer
Jose Matos
Usefull information:
SQL*Plus: Release 11.1.0.7.0 - Production on Fri Mar 4 14:28:34 2011
Copyright (c) 1982, 2008, Oracle. All rights reserved.
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
PL/SQL Release 11.2.0.1.0 - Production
CORE     11.2.0.1.0     Production
TNS for HPUX: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production

Hello
First of all many thanks for the quick answer.
So lets go by parts,
The type attribute used in XML is in CAPS, and it is correct in the DTD (also declared in CAPS) , so correcting my initial post,
DTD:
<!ELEMENT A (B, C)>
<!ATTLIST A TYPE (1|2|3|4|99) #REQUIRED>XML
<A TYPE="99">
   <B>LETTER B </B>
   <C>LETTER C </C>
</A>'Second, the code I'm using to validate the XML document, it's a little big, but here goes. In this document the problematic elements are
PAI element, line 18,19,20;
and PNA element, line 50,51,52 ; the elements declaration using ANY, are the ones used in 11G and the others, not commented in the DTD are the ones of 9i.
<?xml version="1.0" encoding = "iso-8859-1"?>
<!ELEMENT ACTPRDX (UNB, UNH, GIA+, CNT)>
<!ELEMENT UNB (SNDID, RCVID, DTM, INTREF)>
<!ELEMENT SNDID (#PCDATA)>
<!ELEMENT RCVID (#PCDATA)>
<!ELEMENT DTM (#PCDATA)>
<!ELEMENT INTREF (#PCDATA)>
<!ELEMENT UNH (MESREF, VRS, RLS)>
<!ELEMENT MESREF (#PCDATA)>
<!ELEMENT VRS (#PCDATA)>
<!ELEMENT RLS (#PCDATA)>
<!ELEMENT GIA (LOC+, NGI?, PNA?, PAI, EMS+, CNT)>
<!ELEMENT LOC (#PCDATA)>
<!ATTLIST LOC TYPE (1|2|3|4) #REQUIRED>
<!ELEMENT NGI (PGI?, NRG, DTM)>
<!ELEMENT PGI (#PCDATA)>
<!ELEMENT NRG (#PCDATA)>
<!--ELEMENT PAI ANY-->
<!ELEMENT PAI (CUX, MOA)>
<!ATTLIST PAI TYPE (1|2|3|4|99) #REQUIRED>
<!ELEMENT CUX (#PCDATA)>
<!ELEMENT MOA (#PCDATA)>
<!ELEMENT EMS (GIN, PGI, PIA, DGIN, QTY, MEA, EZTX, PNA*, IIO+, SEP*, SEC*, DEV? )>
<!ELEMENT GIN (SID, GID)>
<!ELEMENT SID    (#PCDATA)>
<!ELEMENT GID    (#PCDATA)>
<!ELEMENT PIA (#PCDATA)>
<!ELEMENT DGIN (#PCDATA)>
<!ELEMENT QTY (NDOC, NPAQ)>
<!ELEMENT NDOC    (#PCDATA)>
<!ELEMENT NPAQ    (#PCDATA)>
<!ELEMENT MEA (WTR, WTD?, VOL?, WTV?)>
<!ELEMENT WTR (#PCDATA)>
<!ATTLIST WTR UNIT (GRM) #REQUIRED>
<!ELEMENT WTD (#PCDATA)>
<!ATTLIST WTD UNIT (GRM) #REQUIRED>
<!ELEMENT VOL (LEN, HEI, WID)>
<!ELEMENT LEN (#PCDATA)>
<!ATTLIST LEN UNIT (CMT3) #REQUIRED>
<!ELEMENT HEI (#PCDATA)>
<!ATTLIST HEI UNIT (CMT3) #REQUIRED>
<!ELEMENT WID (#PCDATA)>
<!ATTLIST WID UNIT (CMT3) #REQUIRED>
<!ELEMENT WTV (#PCDATA)>
<!ATTLIST WTV UNIT (KGM) #REQUIRED>
<!ELEMENT EZTX (AGC, AGO, AGD)>
<!ELEMENT AGC    (#PCDATA)>
<!ELEMENT AGO    (#PCDATA)>
<!ELEMENT AGD    (#PCDATA)>
<!-- ELEMENT PNA ANY-->
<!ELEMENT PNA (CLNT?, CONT?, NIF?, NAD)>
<!ATTLIST PNA TYPE (0|1|2) #REQUIRED>
<!ELEMENT CLNT (#PCDATA)>
<!ELEMENT CONT (#PCDATA)>
<!ELEMENT NIF (#PCDATA)>
<!ELEMENT NAD (NME?, ADR?, CPL, CTR?, TEL?, EMAIL?, CTA?,RFF?)>
<!ELEMENT NME (#PCDATA)>
<!ELEMENT ADR (VIA?,RUA, NPOR?, PISO?)>
<!ELEMENT VIA (#PCDATA)>
<!ELEMENT RUA    (#PCDATA)>
<!ELEMENT NPOR    (#PCDATA)>
<!ELEMENT PISO (#PCDATA)>
<!ELEMENT CPL (PTC, CTY)>
<!ELEMENT PTC (#PCDATA)>
<!ELEMENT CTY (#PCDATA)>
<!ELEMENT CTR (#PCDATA)>
<!ELEMENT TEL (#PCDATA)>
<!ELEMENT EMAIL (#PCDATA)>
<!ELEMENT CTA (#PCDATA)>
<!ELEMENT RFF (#PCDATA)>
<!ELEMENT IIO (BID, OID, MEA?, OPR?)>
<!ELEMENT BID (#PCDATA)>
<!ELEMENT OID (#PCDATA)>
<!ELEMENT OPR (#PCDATA)>
<!ELEMENT SEP (SEPID, PAI?)>
<!ELEMENT SEPID (#PCDATA)>
<!ELEMENT SEC (SECID, PAI?)>
<!ELEMENT SECID (#PCDATA)>
<!ELEMENT DEV (#PCDATA)>
<!ELEMENT CNT (#PCDATA)>an example of a XML is:
<?xml version = "1.0" encoding="iso-8859-1"?>
                    <ACTPRDX>
<UNB>
                            <SNDID>DB_TL</SNDID>
                            <RCVID>BD_BD</RCVID>
                            <DTM>20110224025730</DTM>
                            <INTREF>777</INTREF>
                        </UNB>
<UNH>
         <MESREF>666</MESREF>
         <VRS>45</VRS>
         <RLS>6</RLS>
</UNH>
<GIA>
                            <LOC TYPE="1">000099</LOC>
                            <LOC TYPE="2">000094</LOC>
                            <NGI>
                                <PGI>ESCXKKKCUSEKKED00000000000001</PGI>
                                <NRG>50</NRG>
                                <DTM>20110101000001</DTM>
                            </NGI>
                            <PNA  TYPE= "1">
                                <NAD>
                                    <CPL>
                                        <PTC></PTC>
                                        <CTY></CTY>
                                    </CPL>
                                    <TEL></TEL>
                                    <CTA></CTA>
                                    <RFF></RFF>
                                </NAD>
                            </PNA>
                            <PAI TYPE="99">
                            </PAI>
                            <EMS>
                                        <GIN>
                                               <SID>0011110011110111111001</SID>
                                               <GID></GID>
                                        </GIN>
                                        <PGI>KLX</PGI>
                                        <PIA>96S</PIA>
                                        <DGIN>11.01.11</DGIN>
                                                                                <QTY>
                                             <NDOC> 0</NDOC>
                                             <NPAQ> 1</NPAQ>
                                        </QTY>
                                         <MEA>
                                            <WTR UNIT="GRM">1000</WTR>
                                            <WTD UNIT="GRM"></WTD>
                                            <VOL>
                                                   <LEN UNIT="CMT3"> 0</LEN>
                                                   <HEI UNIT="CMT3"> 0</HEI>
                                                   <WID UNIT="CMT3"> 0</WID>
                                            </VOL>
                                            <WTV UNIT="KGM">0</WTV>
                                        </MEA>
                                            <EZTX>
                                              <AGC>000000</AGC>
                                              <AGO>000000</AGO>
                                              <AGD>000000</AGD>
                                        </EZTX>
                                        <PNA TYPE= "1">
                                            <CLNT>999  </CLNT>
                                            <CONT></CONT>
                                            <NAD>
                                        <NME>NAME ENTREGA A</NME>
                                        <ADR>
                                             <VIA></VIA>
                                             <RUA>RUA DA ENTREGA A</RUA>
                                             <NPOR></NPOR>
                                             <PISO></PISO>
                                        </ADR>
                                        <CPL>
                                            <PTC></PTC>
                                            <CTY>MILLADOIRO                    </CTY>
                                        </CPL>
                                        <CTR>ES</CTR>
                                        <TEL></TEL>
                                        <EMAIL></EMAIL>
                                        <RFF></RFF>
                                        </NAD>
                                        </PNA>
                                         <PNA TYPE= "2">
                                    <CLNT></CLNT>
                                    <CONT></CONT>
                                    <NAD>
                                        <NME>NOME_ENTREGA_ENC</NME>
                                        <ADR>
                                             <VIA></VIA>
                                             <RUA>EST. NACIONAL 231</RUA>
                                             <NPOR></NPOR>
                                             <PISO></PISO>
                                        </ADR>
                                        <CPL>
                                            <PTC>1500</PTC>
                                            <CTY>OPORTO </CTY>
                                        </CPL>
                                        <CTR>PT</CTR>
                                        <TEL>219699669</TEL>
                                        <EMAIL></EMAIL>                                       
                                        <RFF></RFF>
                                    </NAD>
                                </PNA>
                                <IIO>
                                        <BID>0015140015140113429001001</BID>
                                        <OID>EKP58962400PT</OID>
                                        <MEA>
                                            <WTR UNIT="GRM"></WTR>
                                              <WTD UNIT="GRM"></WTD>
                                                <VOL>
                                                <LEN UNIT="CMT3"></LEN>
                                                <HEI UNIT="CMT3"></HEI>
                                                <WID UNIT="CMT3"></WID>
                                              </VOL>
                                                 <WTV UNIT="KGM"></WTV>
                                        </MEA>
                                </IIO>
                             </EMS>
                            <CNT>14</CNT>
</GIA>
<CNT>1</CNT>
</ACTPRDX>Many Reguards, and waiting for news

Similar Messages

  • 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 with DTD... Urgent

    Hi all,
    I am using java 1.4
    I have to validate the XML file with the external DTD.
    Can anyone give me the code for that.
    DTD should be external.
    Thanks,
    Vinayak.

    If you are using Solaris , it has xml validation tool "xmllint", using this you can validate your xml against DTD.
    try with "xmllint --help " to see all the option.
    Message was edited by:
    sasrivas

  • XML validation with DTD in java 1.5 not supporting

    Hi,
    I am facing a problem regarding validation of xml file with DTD tag in it.
    I have disabled the parser through setValidating(false) method.
    xml file is not parsed in JRE 1.5.but it is parsed in JRE 1.6.
    Why this is showing such a behavior?
    I have used xerces 2.9.0,xml-api.jar and other jar regarding XML api but still it is giving error.
    please help me.
    please provide a jar file name or its issue resolution in jre 1.5 or 1.4.

    thanks for your prompt reply.
    I required that it should be completely disabled in jre 1.5(jdk1.5 or 1.4).
    I am using DOM Parsing.I have currently disabled with follwowing method,
    builderFactory.setValidating(false);
    builderFactory.setFeature("http://xml.org/sax/features/validation",
         false);
         builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
         builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd",false);
         builderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
         builderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
         factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
    in 1.6 it is working fine but I required that i have to disabled it.but it is giving a error in jre1.5.
    Exception in thread "main" java.lang.AbstractMethodError: javax.xml.parsers.DocumentBuilderFactory.setFeature(Ljava/lang/String;Z)V
    I just want to disable the parsing in jdk version 1.5 or 1.4
    thanks in advance
    anand

  • Not able to run validation using validation.xml & validator-rules.xml

    Hello Friends,
    I am not able to run validation using validation.xml & validator-rules.xml.
    Entire code in running prefectly but no error messages are prompted.
    Following is my code:
    File Name : struts-config.xml
    <struts-config>
    <!-- Form Beans Configuration -->
    <form-beans>
    <form-bean name="searchForm"
    type="com.solversa.SearchForm"/>
    </form-beans>
    <!-- Global Forwards Configuration -->
    <global-forwards>
    <forward name="search" path="/search.jsp"/>
    </global-forwards>
    <!-- Action Mappings Configuration -->
    <action-mappings>
    <action path="/search"
    type="com.solversa.SearchAction"
    name="searchForm"
    scope="request"
    validate="true"
    input="/search.jsp">
    </action>
    </action-mappings>
    <!-- Message Resources Configuration -->
    <message-resources
    parameter="ApplicationResources"/>
    <!-- Validator Configuration -->
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
    <set-property property="pathnames"
    value="/WEB-INF/validator-rules.xml,
    /WEB-INF/validation.xml"/>
    </plug-in>
    </struts-config>
    <br> File Name : <b> validation.xml </b>
    <form-validation>
    <formset>
    <form name="searchForm">
    <field property="name" depends="minlength">
    <arg key="label.search.name" position = "0"/>
    <arg1 name="minlength" key="${var:minlength}" resource="false"/>
    <var>
    <var-name>minlength</var-name>
    <var-value>5</var-value>
    </var>
    </field>
    <field property="ssNum" depends="mask">
    <arg0 key="label.search.ssNum"/>
    <var>
    <var-name>mask</var-name>
    <var-value>^\d{3}-\d{2}-\d{4}$</var-value>
    </var>
    </field>
    </form>
    </formset>
    </form-validation>
    <br> File Name : <b> SearchForm.java </b>
    package com.jamesholmes.minihr;
    import java.util.List;
    import org.apache.struts.validator.ValidatorForm;
    public class SearchForm extends ValidatorForm
    private String name = null;
    private String ssNum = null;
    private List results = null;
    public void setName(String name) {
    this.name = name;
    public String getName() {
    return name;
    public void setSsNum(String ssNum) {
    this.ssNum = ssNum;
    public String getSsNum() {
    return ssNum;
    public void setResults(List results) {
    this.results = results;
    public List getResults() {
    return results;
    <br> File Name : <b> SearchAction.java </b>
    package com.jamesholmes.minihr;
    import java.util.ArrayList;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    public final class SearchAction extends Action
    public ActionForward execute(ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws Exception
    EmployeeSearchService service = new EmployeeSearchService();
    ArrayList results;
    SearchForm searchForm = (SearchForm) form;
    // Perform employee search based on what criteria was entered.
    String name = searchForm.getName();
    if (name != null && name.trim().length() > 0) {
    results = service.searchByName(name);
    } else {
    results = service.searchBySsNum(searchForm.getSsNum().trim());
    // Place search results in SearchForm for access by JSP.
    searchForm.setResults(results);
    // Forward control to this Action's input page.
    return mapping.getInputForward();
    <br> File Name : <b> EmployeeSearchService.java </b>
    package com.jamesholmes.minihr;
    import java.util.ArrayList;
    public class EmployeeSearchService
    /* Hard-coded sample data. Normally this would come from a real data
    source such as a database. */
    private static Employee[] employees =
    new Employee("Bob Davidson", "123-45-6789"),
    new Employee("Mary Williams", "987-65-4321"),
    new Employee("Jim Smith", "111-11-1111"),
    new Employee("Beverly Harris", "222-22-2222"),
    new Employee("Thomas Frank", "333-33-3333"),
    new Employee("Jim Davidson", "444-44-4444")
    // Search for employees by name.
    public ArrayList searchByName(String name) {
    ArrayList resultList = new ArrayList();
    for (int i = 0; i < employees.length; i++) {
    if (employees.getName().toUpperCase().indexOf(name.toUpperCase()) != -1) {
    resultList.add(employees[i]);
    return resultList;
    // Search for employee by social security number.
    public ArrayList searchBySsNum(String ssNum) {
    ArrayList resultList = new ArrayList();
    for (int i = 0; i < employees.length; i++) {
    if (employees[i].getSsNum().equals(ssNum)) {
    resultList.add(employees[i]);
    return resultList;
    <br> File Name : <b> Employee.java </b>
    package com.solversa;
    public class Employee
         private String name;
         private String ssNum;
         public Employee(String name, String ssNum) {
         this.name = name;
         this.ssNum = ssNum;
         public void setName(String name) {
         this.name = name;
         public String getName() {
         return name;
         public void setSsNum(String ssNum) {
         this.ssNum = ssNum;
         public String getSsNum() {
         return ssNum;
    Pls help me out.
    Not able to prompt errors.

    Hello Friends,
    I am not able to run validation using
    validation.xml & validator-rules.xml.
    Entire code in running prefectly but no error
    messages are prompted.
    Following is my code:
    File Name : struts-config.xml
    <struts-config>
    <!-- Form Beans Configuration -->
    <form-beans>
    <form-bean name="searchForm"
    type="com.solversa.SearchForm"/>
    ans>
    <!-- Global Forwards Configuration -->
    <global-forwards>
    <forward name="search" path="/search.jsp"/>
    global-forwards>
    <!-- Action Mappings Configuration -->
    <action-mappings>
    <action path="/search"
    type="com.solversa.SearchAction"
    name="searchForm"
    scope="request"
    validate="true"
    input="/search.jsp">
    tion>
    </action-mappings>
    <!-- Message Resources Configuration -->
    <message-resources
    parameter="ApplicationResources"/>
    <!-- Validator Configuration -->
    <plug-in
    className="org.apache.struts.validator.ValidatorPlugI
    ">
    <set-property property="pathnames"
    value="/WEB-INF/validator-rules.xml,
    /WEB-INF/validation.xml"/>
    >
    </struts-config>
    <br> File Name : <b> validation.xml </b>
    <form-validation>
    <formset>
    <form name="searchForm">
    <field property="name" depends="minlength">
    <arg key="label.search.name" position = "0"/>
    <arg1 name="minlength" key="${var:minlength}"
    resource="false"/>
    <var>
    <var-name>minlength</var-name>
    <var-value>5</var-value>
    </var>
    </field>
    <field property="ssNum" depends="mask">
    <arg0 key="label.search.ssNum"/>
    <var>
    <var-name>mask</var-name>
    <var-value>^\d{3}-\d{2}-\d{4}$</var-value>
    </var>
    </field>
    /form>
    </formset>
    form-validation>
    <br> File Name : <b> SearchForm.java </b>
    package com.jamesholmes.minihr;
    import java.util.List;
    import org.apache.struts.validator.ValidatorForm;
    public class SearchForm extends ValidatorForm
    private String name = null;
    private String ssNum = null;
    private List results = null;
    public void setName(String name) {
    this.name = name;
    public String getName() {
    return name;
    public void setSsNum(String ssNum) {
    this.ssNum = ssNum;
    public String getSsNum() {
    return ssNum;
    public void setResults(List results) {
    this.results = results;
    public List getResults() {
    return results;
    <br> File Name : <b> SearchAction.java </b>
    package com.jamesholmes.minihr;
    import java.util.ArrayList;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    public final class SearchAction extends Action
    public ActionForward execute(ActionMapping
    mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws Exception
    EmployeeSearchService service = new
    EmployeeSearchService();
    ArrayList results;
    SearchForm searchForm = (SearchForm) form;
    // Perform employee search based on what criteria
    was entered.
    String name = searchForm.getName();
    if (name != null && name.trim().length() > 0) {
    results = service.searchByName(name);
    else {
    results =
    service.searchBySsNum(searchForm.getSsNum().trim());
    // Place search results in SearchForm for access
    by JSP.
    searchForm.setResults(results);
    // Forward control to this Action's input page.
    return mapping.getInputForward();
    <br> File Name : <b> EmployeeSearchService.java </b>
    package com.jamesholmes.minihr;
    import java.util.ArrayList;
    public class EmployeeSearchService
    /* Hard-coded sample data. Normally this would come
    from a real data
    source such as a database. */
    ivate static Employee[] employees =
    new Employee("Bob Davidson", "123-45-6789"),
    new Employee("Mary Williams", "987-65-4321"),
    new Employee("Jim Smith", "111-11-1111"),
    new Employee("Beverly Harris", "222-22-2222"),
    new Employee("Thomas Frank", "333-33-3333"),
    new Employee("Jim Davidson", "444-44-4444")
    // Search for employees by name.
    public ArrayList searchByName(String name) {
    ArrayList resultList = new ArrayList();
    for (int i = 0; i < employees.length; i++) {
    if
    (employees.getName().toUpperCase().indexOf(name.toU
    pperCase()) != -1) {
    resultList.add(employees[i]);
    return resultList;
    // Search for employee by social security number.
    public ArrayList searchBySsNum(String ssNum) {
    ArrayList resultList = new ArrayList();
    for (int i = 0; i < employees.length; i++) {
    if (employees[i].getSsNum().equals(ssNum)) {
    resultList.add(employees[i]);
    return resultList;
    <br> File Name : <b> Employee.java </b>
    package com.solversa;
    public class Employee
         private String name;
         private String ssNum;
         public Employee(String name, String ssNum) {
         this.name = name;
         this.ssNum = ssNum;
         public void setName(String name) {
         this.name = name;
         public String getName() {
         return name;
         public void setSsNum(String ssNum) {
         this.ssNum = ssNum;
         public String getSsNum() {
         return ssNum;
    Pls help me out.
    Not able to prompt errors.
    Hi,
    Your error message are not displaying because u does not made Message-Resoucrce property file (Resource Bundle) when you make it .
    give it entry in
    struts-config.xml
    <message-resources parameter="ApplicationResources" />
    and
    define key and corresponding error message to key in this ApplicationResources i.e
    #Error Resources
    label.search.ssNum=Plz Enter correct ssNum

  • XML Validation using java for SQL Injection and script validation

    I have an input coming from xml file.
    I have to read that input and validate the input against sql injections and scripts.
    I require help now how to read this xml data and validate against the above two options.
    I am a java developer.
    in this context what is marshelling?

    http://www.ibm.com/developerworks/library/x-javaxmlvalidapi.html?ca=dgr-lnxw07Java-XML-Val
    http://java.sun.com/j2se/1.5.0/docs/api/javax/xml/validation/package-summary.html
    The following code validates the xml against a xml schema
    // define the type of schema - we use W3C:
    String schemaLang = "http://www.w3.org/2001/XMLSchema";
    SchemaFactory factory = SchemaFactory.newInstance(schemaLang);
    Schema schema = factory.newSchema(new StreamSource("sample.xsd"));
    Validator validator = schema.newValidator();
    // at last perform validation:
    validator.validate(new StreamSource("sample.xml"));Message was edited by:
    haishai

  • XML validation using javax.xml.validation

    Hello,
    I am trying to validate some xml against my xsd.
    Here is my xml:
    <host>
        <status>Unknown</status>
    </host>Here is my xsd:
    <?xml version="1.0"?>
                                                                                                                                                                 <xsd:schema targetNamespace="blah"
            xmlns:tns="blah"
            xmlns:xsd="blah">
    <xsd:simpleType name="Status">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="Unknown"/>
    </xsd:restriction>
    </xsd:simpleType>
    <xsd:element name="host">
       <xsd:complexType>
         <xsd:all>
           <xsd:element name="status" type="tns:Status"/>
         </xsd:all>
       </xsd:complexType>
    </xsd:element>
                                                                                                                                                                 </xsd:schema>My test code is:
            try
                DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
                Document document = parser.parse(new File("test.xml"));
                // Create a SchemaFactory capable of understanding WXS schemas.
                SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
                // Load a WXS schema, represented by a Schema instance.
                StreamSource schemaFile = new StreamSource(new File("schema.xsd"));
                Schema schema = factory.newSchema(schemaFile);
                // Create a Validator object, which can be used to validate the document
                Validator validator = schema.newValidator();
                // Validate the DOM tree.
                validator.validate(new DOMSource(document));
            catch(Exception e)
                fail("XML validation failed: " + e.getMessage());
            }I get the following error:
    ERROR: 'cvc-elt.1: Cannot find the declaration of element 'host'.'
    If i replace "type=tns:Status' in the "status" element with just "type=string", it works fine.
    Does anyone have any idea what the problem is?
    Thank you,
    David

    To daft_davy:
    1. Your XSD document is invalid: the xmlns attribute of schema documents must always have the following value: "http://www.w3.org/2001/XMLSchema"
    All other values will result in the following validation error:
    org.xml.sax.SAXParseException: s4s-elt-schema-ns: The namespace of element 'schema' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'.
    Your XSD should look like this:
    <?xml version="1.0"?>
    <xsd:schema targetNamespace="blah" xmlns:tns="blah" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
      <xsd:simpleType name="Status">
        <xsd:restriction base="xsd:string">
          <xsd:enumeration value="Unknown"/>
        </xsd:restriction>
      </xsd:simpleType>
      <xsd:element name="host">
        <xsd:complexType>
          <xsd:all>
            <xsd:element name="status" type="tns:Status"/>
          </xsd:all>
        </xsd:complexType>
      </xsd:element>
    </xsd:schema>2. Your XML document does not match the XSD schema (even if you use the one above) for the following reasons:
    a) The root element of the XML document must be associated with the namespace defined by the targetNamespace attribute of the schema.
    b) The "blah" namespace at the element <status> in the XML document has to be undeclared because there is no namespace declaration to this element in the schema document either. There are to ways to do this:
    <host xmlns="blah">
      <status xmlns="">Unknown</status>
    </host>or:
    <xxx:host xmlns:xxx="blah">
      <status>Unknown</status>
    </xxx:host>
    To watertownjordan:
    The namespace URI can be virtually any string, so you don't need to specify a valid URI to define a namespace.

  • XML validation against DTD

    Hi,
    I have an application that receives XML from an external source. The XML received does not have the XML version and the doc type declaration lines. I want to validate the XML against a DTD.
    One dirty way of doing this is to open the XML received and prepend the XML versions and doctype lines to it. And then parse the XML. But is it the right way to do it?
    What I would like to know is that does the XML parser provide any API which can tell it to validate an XML document against a certain DTD.

    Yes, there is an API to do this. You have to do something like this:
    DocumentBuilderFactory dbf          =DocumentBuilderFactory.newInstance();
    dbf.setValidating(true);
    DocumentBuilder db = dbf.newDocumentBuilder();
    XMLErrors eh = new XMLErrors(frame);
    db.setErrorHandler(eh);
    Document doc = db.parse(f);
    (where f is the XML file)
    In this example, the class XMLErrors is used as the ErrorHandler. XMLErrors extends the DefaultHandler class and provides the user with information about the various error levels. A call to the over-ridden "error" method notifies the user (using a Dialog box) that the document doesn't meet the DTD.
    Hope this helps.

  • Error while Validating xml against a schema using jaxp

    Hi All,
    Following code validates xml against a schema using JAXP .It gives SAXNotRecognizedException error when you run the program.
    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";
    SAXParserFactory myFactory = SAXParserFactory.newInstance();
    myFactory.setNamespaceAware(true);
    myFactory.setValidating(true);
    javax.xml.parsers.SAXParser parser;
    String filename = "C:/Note.xml";
    File xmlFile = new File(filename);
    try
         DefaultHandler handler = new DefaultHandler();
         parser = myFactory.newSAXParser();
         parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
         parser.parse(xmlFile, handler);
    catch (ParserConfigurationException e)
         // TODO Auto-generated catch block
         e.printStackTrace();
    catch (SAXException e)
         // TODO Auto-generated catch block
         e.printStackTrace();
    catch (IOException e)
         // TODO Auto-generated catch block
         e.printStackTrace();
    Error Details :
    org.xml.sax.SAXNotRecognizedException: http://java.sun.com/xml/jaxp/properties/schemaLanguage
         at org.apache.xerces.framework.XMLParser.setProperty(XMLParser.java:1682)
         at org.apache.xerces.parsers.SAXParser.setProperty(SAXParser.java:770)
         at org.apache.xerces.jaxp.SAXParserImpl.setProperty(SAXParserImpl.java:183)
    How do i fix the above mentioned problem ?
    Thanks in Advance.
    Ansh

    Validate with the JAXP DOMParser instead of the JAXP SAXParser.
    To validate with a SAXParser use the xerces SAXParser.
    thanks,
    Deepak

  • XML validation using Oracle XML parser v2

    Not sure if this is the right forum for this question as I didn't found any.
    I had a tough time trying to build an XMLSchema (Oracle XML Parser V2) object from the input schema having include/import. Actually I am working on a Java program to validate the input xml with input schema using Oracle XML parser v2 api.
    The issue is that the code doesn't work for schema that has some "include" in it. The code is working fine for the schema without any import/include. Here is the lines of code -
    XSDBuilder builder = new XSDBuilder();
    schema = builder.build(new InputSource(xsdReader));
    I am writing this in JDeveloper. The error is -
    oracle.xml.parser.schema.XSDException: Can not build schema 'http://www.fpml.org/2005/FpML-4-2' located at 'xsd\FpML42\xml\fpml-fx-4-2.xsd'
    I also tried creating the EntityResolver to specify the path of included schema. But that doesn't solves the problem.
    I am not sure whether parser is able to locate the included schema or not.The main schema and included schema are all in same folder. The included schema is perfectly fine and has no errors.
    Please help if you have encountered this issue and resolved it. I will really appreciate any pointers or clue to solve this issue.
    Thanks.

    Thanks for the reply. But it does not seem to be working. Am I missing something
    I put <TrxDate xsi:nil="true"/> but still getting error.
    Here's my xsd:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    elementFormDefault="qualified">
    <xsd:element name="TrxDate" type="xsd:date" nillable="true" />
    XML:
    <?xml version="1.0" encoding="UTF-8" ?>
    <ServiceRequest>
    <TrxDate nil="true"/>
    </ServiceRequest>

  • Validating user login using XML

    Hi,
    Given a set of user information in XML, is it possible
    to validate the user login without any front end login modules? Can we introduce a J2EE project with some helpers or listeners in such a way that whenever the URL is hit, the helper/listener takes the XML from request?And after extracting user info from XML, validating the same by interacting with UME?Can I get some suggestions in this ground? Thanks..

    Depends on how you are asking for input. For instance with a jtextfield, you create a plaindocument object and pass that into what component you want to have validation.... That a look at the api for reference...
    http://java.sun.com/j2se/1.3/docs/api/javax/swing/text/PlainDocument.html
    But, if all you want to do is convert a string to an integer try
    Integer.parseInt("12345");
    and check if that throws an exception...

  • 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

  • SAX Parser XML Validation Problems

    Hi,
    I’m having problems getting an xml document to validate within Weblogic 8.1. I am trying to parse a document that references both a dtd and xsd. Both the schema and dtd reference need to be substituted so they use local paths. I specify the schema the parser should use and have created an entityResolver to change the dtd reference.
    When this runs as a standalone app from eclipse the file parses and validates without a problem. When deployed to the app server the process seems to be unable read the contents of the dtd. Its not that it cannot find the file (no FileNotFoundException is thrown but this can be created if I delete the dtd) rather it seems to find no declared elements.
    Initial thought was that the code didn’t have access to read the dtd from its location on disk, to check I moved the dtd to within the deployed war and reference as a resource. The problem still persists.
    Code Snippet:
    boolean isValid = false;
    try {
         // Create and configure factory
    SAXParserFactory factory = SAXParserFactoryImpl.newInstance();
    factory.setValidating(true);
    factory.setNamespaceAware(true);
    // To be notified of validation errors in the XML document,
    // add a custom error handler to the document builder
    PIMSFeedFileValidationHandler handler
    = new PIMSFeedFileValidationHandler();
         // Create and Configure Parser
    SAXParser parser = factory.newSAXParser();
    parser.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
    parser.setProperty(NAMESPACE_PROPERTY_KEY, getSchemaFilePath());
         // Set reader with entityResolver for dtd
    XMLReader xmlReader = parser.getXMLReader();
    xmlReader.setEntityResolver(new SAXEntityResolver(this.dtdPath));
    // convert file to URL, as it is a remote file
    URL url = super.getFile().toURL();
    // Open an input stream and parse
    InputStream is = url.openStream();
    xmlReader.setErrorHandler(handler);
    xmlReader.parse(new InputSource(is));
    is.close();
    // get the result of parsing the document by checking the
    // errorhandler's isValid property
    isValid = handler.isValid();
    if (!isValid) {
    LOGGER.warn(handler.getMessage());
    LOGGER.debug("XML file is valid XML? " + isValid);
    } catch (ParserConfigurationException e) {
    LOGGER.error("Error parsing file", e);
    } catch (SAXException e) {
    LOGGER.error("Error parsing file", e);
    } catch (IOException e) {
    throw new FeedException(e);
    return isValid;
    See stack trace below for a little more info.
    2005-01-28 10:24:09,217 [DEBUG] [file] - Attempting validation of file 'cw501205.wa1.xml' with schema at 'C:/pims-feeds/hansard/schema/hansard-v1-9.xsd'
    2005-01-28 10:24:09,217 [DEBUG] [file] - Entity Resolver is using DTD path file:C:/Vignette/runtime_services/8.1/install/common/nodemanager/
    VgnVCMServer/stage/pims-hansard/pims-hansard.war/WEB-INF/classes/com/morse/pims/cms/feed/sax/ISO-Entities.dtd
    2005-01-28 10:24:09,227 [DEBUG] [file] - Creating InputSource at: file:C:/Vignette/runtime_services/8.1/install/common/nodemanager/VgnVCMServer/stage/pims-hansard/pims-hansard.war/WEB-INF/classes/com/morse/pims/cms/feed/sax/ISO-Entities.dtd
    2005-01-28 10:24:09,718 [WARN ] [file] - org.xml.sax.SAXParseException: Element type "Hansard" must be declared.
    org.xml.sax.SAXParseException: Element type "Session" must be declared.
    org.xml.sax.SAXParseException: Element type "DailyRecord" must be declared.
    org.xml.sax.SAXParseException: Element type "Volume" must be declared.
    org.xml.sax.SAXParseException: Element type "Written" must be declared.
    org.xml.sax.SAXParseException: Element type "WrittenHeading" must be declared.
    org.xml.sax.SAXParseException: Element type "Introduction" must be declared.
    … continues for all the elements in the doc
    2005-01-28 10:24:10,519 [DEBUG] [file] - XML file is valid XML? false
    2005-01-28 10:24:10,519 [WARN ] [file] - Daily Part file 'cw501205.wa1.xml' was not valid XML and was not processed.
    Has anybody seen this behavior before with weblogic and if so how have you resolved the issue.
    Thanks in Advance
    Adam

    Hi David,
    I have checked the ejb-jar.xml file and there is no duplicate values in it and the other things is that the same application is been deployed on OAS 10G and websphere and its working fine. In the forum someone has replied to a similar problem that there is bug in Weblogic 10.3 and its CR no 376292. I am not sure about it, does anyone any information about it.
    Thanks and Regards
    Deepak Dani

  • 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

  • How to disable xml validation

    I'm trying to write an SVG parser using Xerces. The problem is that when the SVG file contains the doctype tag <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">my program throws the following exception:
    java.net.UnknownHostException: www.w3.org
            at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:177)
            at java.net.Socket.connect(Socket.java:507)
            at java.net.Socket.connect(Socket.java:457)
    etc.If I remove <!DOCTYPE> tag, it works fine. According to what I read here, it's necessary to disable XML validation. The Xerces API documentation says that there is a method setValidation() in org.apache.xerces.framework.XMLParser but I can't locate it. Moreover, I don't see any org.apache.xerces.framework package in Xerces supplied with NetBeans 5.0 nor in Xerces 2.8.0 downloaded from apache.org (the XMLParser class available to me is located in org.apache.xerces.parsers).
    My question is simple:
    How to disable XML validation if the setValidation() method is not avaliable
    OR
    how to make the setValidation method available to my program?
    I'm really confused :(
    Here is the code:
    package svgviewer;
    import java.io.File;
    import org.w3c.dom.*;
    import org.w3c.dom.traversal.*;
    import org.apache.xerces.parsers.*;
    public class SVGFileParser {
        public void parse(String filename) throws Exception {
            File file = new File(filename);
            DOMParser parser = new DOMParser();
            parser.parse(file.toURL().toString()); //exception is thrown if doctype tag is present in the svg file

    You're solving the wrong problem here. Turning off validation won't help, because DTDs don't only do validation. Even non-validating parsers have to read the DTD in case it contains entity definitions, for example.
    If you want to stop the parser from looking for the DTD then you write a EntityResolver and apply it to the parser. The EntityResolver should be just like the one in the example in the API docs except it should return new InputSource(new StringReader("")).

Maybe you are looking for

  • Is there any function module which gives open invoices &open amount?

    Hello All, I want to use function module which gives open invoices with open amount. I know 'CUSTOMER_OPEN_ITEMS'  'BAPI_AR_ACC_GETOPENITEMS' function which gives open invoices but does not give open amount. Can anyone help me to find such function?

  • External Hard Drive Failures after iMac internal drive replaced

    I was one of those lucky ppl who had to have my internal 1TB Seagate HDD replaced due to the recall. It was replaced on Friday. After the drive was replaced (with another Seagate, ***?), I cloned my previous system back to the new drive (restoring fr

  • JBO-26061: Error while opening JDBC connection

    Hi, I have pasted this thread in Jdev forum for several days. But I still cannot solve this problem. The ADF application works fine in Jdev 11g's default server. After the login page, it can go to the correct jspx page. I create a new weblogic domain

  • How can I put Service charge to receive money from customer in Sales Return

    My company will receive the Restocking fee from customer when customer want to return the goods. I create a Sales Return Document for sales return but I can't put the service charge to charge my customer in the sales return document. If there is any

  • TS2972 Have to keep restarting iTunes for homeshare

    I replaced my two Apple TV 2s with Apple TV3s, and now I have to keep restarting iTunes on my iMac to see my libary. It was flawless before.  I very rarely had to restart iTunes. I have an iMac (2011, i7), hardwired to an airport extreme, and then th