W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2002

RE: Error in xsd validation....

From: Tom Preston <tpreston@amadeusboston.com>
Date: Wed, 6 Feb 2002 09:53:38 -0500
Message-ID: <498B0C8F9141D511927B009027B1138745D270@email-temp.vacation-corp.com>
To: Sanjaya Kasthuri Arachchi <sanjayakas@hotmail.com>, xmlschema-dev@w3.org
The first time you call parser.parse(aString); where aString is an instance
of type String.  This String is a LOCATION of an xml file to be parsed.
THis works.

In the second case you AGAIN call parser.parse(aString); where aString is
also an instance of type String.  BUT this String is an XML document
represented as a String not the LOCATION of the file.  The
parser.parse(String) method String parameter is supposed to be an xml file
LOCATION.  It appears that it attempts to resolve the String into a Location
by making it a java.net.URL instance.  When it tries to construct a
java.net.URL with "The above mentioned xml" it will fail with a
MalformedURLException.

The first way was correct.

TOm


-----Original Message-----
From: Sanjaya Kasthuri Arachchi [mailto:sanjayakas@hotmail.com]
Sent: Wednesday, February 06, 2002 8:11 AM
To: xmlschema-dev@w3.org
Subject: Error in xsd validation....




Hi All,

   I am trying to validate a xml file against a xsd file. My code is this :

            DOMParser parser = new DOMParser();
            parser.setFeature("http://xml.org/sax/features/validation", 
true);
            
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
            ErrorChecker errors = new ErrorChecker();
            parser.setErrorHandler(errors);
            parser.parse("Token.xml");
            Document doc = parser.getDocument();

   This works fine and it validates the Token.xml file, which is this :

   <ValidateIdentificationTokenRequest  
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    
xsi:noNamespaceSchemaLocation="Token.xsd">
      <InputATBFlightCoupon>
          <UnparsedData>BOARDCPN#D8303</UnparsedData>
      </InputATBFlightCoupon>
   </ValidateIdentificationTokenRequest>

   But my problem is, when I input the same xml as a String ;

           String str = "The above mentioned xml";
           parser.parse(str);

   it throws an exception.

java.net.MalformedURLException: no protocol:  
<ValidateIdentificationTokenRequest        
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       
xsi:noNamespaceSchemaLocation="/Token.xsd">
<InputATBFlightCoupon><UnparsedData>BOARDCPN#D8303</UnparsedData>
</InputATBFlightCoupon></ValidateIdentificationTokenRequest>

   at java.net.URL.<init>(URL.java:473)
   at java.net.URL.<init>(URL.java:376)
   at java.net.URL.<init>(URL.java:330)
   at 
org.apache.xerces.impl.XMLEntityManager.startEntity(XMLEntityManager.java:71
9)
   at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity    
(XMLEntityManager.java:666)
   atorg.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource
   (XMLDocumentScannerImpl.java:251)
   at org.apache.xerces.parsers.StandardParserConfiguration
   .setInputSource(StandardParserConfiguration.java:440)
   at org.apache.xerces.parsers.StandardParserConfiguration.parse
   (StandardParserConfiguration.java:520)
   at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:148)
   at org.apache.xerces.parsers.DOMParser.parse(DOMParser.java:152)
   at ssd.XMLTest.main(XMLTest.java:37)


   Please be kind enough to help me to solve this problem. Thanks in 
advance.


_________________________________________________________________
Send and receive Hotmail on your mobile device: http://mobile.msn.com
Received on Wednesday, 6 February 2002 09:53:33 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:26 GMT