xml-soap-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Das, Kuntal" <Kuntal....@Schwab.com>
Subject Tried the validator.....
Date Sat, 02 Jun 2001 00:19:26 GMT
Hi,
	I tried that code and it did seem to validate the schema. But it
didn't validate the xml document whether it is compling with the schema. I'm
sending u the code sample, the xml file and the schema(.xsd). Maybe that'll
help. Once again, I don't need a "Schema validator", all I need is a
validator which will say that this .xml file complies or follows the
constraints or rules mentioned in the schema(.zsd).


ValidateXML.java
**********************
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;
import org.xml.sax.SAXException;
import org.w3c.dom.*;


public class ValidateXML
{

	public static void main(String []a) throws Exception
	{
		try
		{
			DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();
			factory.setValidating(true);
			factory.setNamespaceAware(true);
			MyErrorHandler err = new MyErrorHandler();
//inherited from org.xml.sax.ErrorHandler


			DocumentBuilder builder =
factory.newDocumentBuilder();
			builder.setErrorHandler(err);

			Document mydoc = builder.parse(new InputSource
	
("file:///C:/experiments/DomesticMobileService/schemas/DataException.xml"));
		}
		catch(SAXException se)
		{
			System.out.println("Caught SAXException : "+se);
		}
	}
}

class MyErrorHandler implements org.xml.sax.ErrorHandler
{
	public void warning(SAXParseException exception) throws SAXException
    {
		System.out.println("This is a warning : "+exception);
    }
	
	public void error(SAXParseException exception) throws SAXException
	{
		System.out.println("This is an error : "+exception);
	}
    
	public void fatalError(SAXParseException exception) throws
SAXException
	{
		System.out.println("This is a fatalError : "+exception);
	}
}


*********************
Common.xsd
*********************
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema 
	targetNamespace="http://pb.schwab.com/schema/common/" 
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	xmlns="http://pb.schwab.com/schema/common/"
	elementFormDefault="qualified"
	attributeFormDefault="unqualified">

    <!-- enum ExcpSource -->
    <xsd:simpleType name="ExcpSource">
        <xsd:restriction base="xsd:string">
            <xsd:enumeration value="MAINFRAME"/>
            <xsd:enumeration value="SENTRY"/>
            <xsd:enumeration value="MIDDLEWARE"/>
        </xsd:restriction>
    </xsd:simpleType>

    <xsd:group name="systemExceptionElements">
        <xsd:sequence>
            <xsd:element name="moduleId" type="xsd:string"/>
            <xsd:element name="messageText" type="xsd:string"/>
            <xsd:element name="addtnlText" type="xsd:string"/>
            <xsd:element name="schProcRtrnCd" type="xsd:int"/>
            <xsd:element name="appRtrnCd" type="xsd:int"/>
            <xsd:element name="expSource" type="ExcpSource"/>
        </xsd:sequence>
    </xsd:group>


    <xsd:complexType name="DataException">
        <xsd:sequence>
            <xsd:group ref="systemExceptionElements"/>
            <xsd:element name="fieldName" type="xsd:string"/>
            <xsd:element name="fldMsg" type="xsd:string"/>
            <xsd:element name="fieldOccurs" type="xsd:positiveInteger"/>
            <xsd:element name="fldMsgCd" type="xsd:positiveInteger"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="SystemException">
        <xsd:sequence>
            <xsd:group ref="systemExceptionElements"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="AccessToken">
        <xsd:sequence>
            <xsd:element name="userID" type="xsd:string"/>
            <xsd:element name="userIDType" type="xsd:string"/>
            <xsd:element name="sessionToken" type="xsd:string"/>
            <xsd:element name="sentryRegion" type="xsd:string"/>
            <xsd:element name="wirelessId" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="AccessTokenEx">
        <xsd:sequence>
            <xsd:element name="userID" type="xsd:string"
                minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="sessionToken" type="xsd:string"
                minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="userIDType" type="xsd:string"
                minOccurs="0" maxOccurs="unbounded"/>
            <xsd:element name="sentryRegion" type="xsd:string"/>
            <xsd:element name="wirelessId" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="ErrorMessage">
        <xsd:sequence>
            <xsd:element name="errorMessageText" type="xsd:string"/>
            <xsd:element name="errorValue" type="xsd:string"/>
            <xsd:element name="errorMessageId" type="xsd:int"/>
            <xsd:element name="errorMessagePriorityCode" type="xsd:short"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:complexType name="SecurityPrice">
        <xsd:sequence>
            <xsd:element name="fractionalString" type="xsd:string"/>
        </xsd:sequence>
    </xsd:complexType>
</xsd:schema>

*****************
DataException.xml
*****************

<common:dataException 
	xmlns="http://pb.schwab.com"
	xmlns:common="http://pb.schwab.com/schema/common/"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:noNameSpaceSchemaLocation="common.xsd">
	
    <messageText>INVALID PASSWORD</messageText>
    <addtnlText/>
    <schProcRtrnCd>0</schProcRtrnCd>
    <appRtrnCd>9045</appRtrnCd>
    <expSource>SENTRY</expSource>
    <fieldName/>
    <fldMsg/>
    <fieldOccurs>0</fieldOccurs>
    <moduleId/>
</common:dataException>

************************************************

Help !!!

Thanks,
Kuntal Das
Charles Schwab & Co., Inc.
Wireless Technology
45 Fremont, SF
Email : kuntal.das@schwab.com
Phone : (415)667-4322
Live life to the brim.................



Mime
View raw message