Hi
 
I working  whit Web service in java,  axis and  Xerces2,  this web service get like paremeter  an  XML,  the which use a schema whith restriction, but the validations no work, when i introduce a bad parameter.
 
Note: The error of validation are write by catalina.out
 
 
the xsd and xml was generate whith xmlspy
 
 
<?xml version="1.0" encoding="UTF-8"?>
<data xmlns:xsi="
http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="1.xsd">
 <data1>123</data1>
 <data2>1213</data2>
</data>
 
<?xml version="1.0" encoding="UTF-8"?>
<!--W3C Schema generated by XMLSPY v5 rel. 4 U (
http://www.xmlspy.com)-->
<xs:schema xmlns:xs="
http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
 <xs:element name="data">
  <xs:complexType>
   <xs:sequence>
    <xs:element ref="data1"/>
    <xs:element ref="data2"/>
   </xs:sequence>
  </xs:complexType>
 </xs:element>
 <xs:element name="data1" type="xs:number"/>
 <xs:element name="data2" type="xs:number"/>
</xs:schema>
 
 
 
 
The program is :
 
 
import javax.xml.parsers.*;
import org.apache.xpath.*;
import org.w3c.dom.*;
import org.apache.xpath.*;
 
import java.util.Hashtable;
 
import org.apache.xerces.parsers.DOMParser;
import org.xml.sax.ErrorHandler;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
 
import org.xml.sax.SAXParseException;
import org.xml.sax.SAXException;
import org.xml.sax.SAXNotRecognizedException;
import org.xml.sax.SAXNotSupportedException;
 
import org.xml.sax.InputSource;
import org.xml.sax.*;
import java.io.IOException;
import java.io.StringReader;
import java.io.*;
 
public class z {
  

   // Funciones Xpaht
   //=======================================================================
    private static String findValue(Node node, String xql) throws Exception
    {
        // se validan los parametros de entrada
        if( (xql == null) || (xql.length() == 0) ) {
          throw new Exception("ERROR: findValue llamado con segundo parametro(xql) vacio");
        }
        if(node == null) {
            throw new Exception("ERROR: findValue llamado con primer parametro(node) nulo");
         throw new Exception("ERROR: findValue llamado con primer parametro(node) nulo");
        }
        return getValorHijoDependiendoDeQuery(XPathAPI.selectSingleNode(node,xql) );
    }
 

    private static String getValorHijoDependiendoDeQuery ( Node node )
    {
        NodeList NodosHijos;
        StringBuffer valor = new StringBuffer();
        NodosHijos =  node.getChildNodes();
        for(int i=0; i < NodosHijos.getLength(); i++ )
        {
            if( NodosHijos.item(i).getNodeType() == Node.TEXT_NODE )
            {
                valor.append(NodosHijos.item(i).getNodeValue());
            }
        }
        return valor.toString();
    }
 
    public String getz(String xmlString) {
 
        String sxm=null;
        String respRenta = null;
        DOMParser parser = new DOMParser();
 

        try {

            // paso 1 recibe xml desde parametro y valida el esquema
            //=======================================================================
 

            parser.setFeature ("http://xml.org/sax/features/namespaces", true);
            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);
 
            parser.setFeature("http://apache.org/xml/features/dom/defer-node-expansion", true);
            parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error", true);
 
           
            parser.parse(new InputSource(new StringReader(xmlString)) );
            Document document = parser.getDocument();
 
 
            //=======================================================================
            Element root        = document.getDocumentElement();
            Node configNode     = root.getFirstChild();
            NodeList childNodes = configNode.getChildNodes();
 
            // Forma URL 
            //=======================================================================
            String URL  = "d1=" + findValue( root, "/data/d1" ) + "&";
                   URL += "d2=" + findValue( root, "/data/d2" ) + "&";
                   URL += "d3=" + findValue( root, "/data/d3" ) ;

                      return  URL;
 
        } catch (SAXNotRecognizedException ex4) {
             return "ERROR SAXNotRecognizedException: " + ex4.toString();
        } catch (SAXNotSupportedException ex5) {
             return "ERROR SAXNotSupportedException: " + ex5.toString();
        } catch (SAXParseException ex1) {
             return "ERROR SAXParseException: " + ex1.toString();
        } catch (SAXException ex) {
             return "ERROR SAXException: " + ex.toString();
             //return "Error SAXException: NO PUDE PARSEAR";
        } catch (Exception e2) {
             return "ERROR Exception: " + e2.toString()+ "chao";
             //return "Error Exception : NO PUDE PARSEAR";
        }
      }
 
Gracias.-
Zulema Olguin T.
Chile

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to