Saxon as validating XML Parser

Hello,

I'm having a problem using Saxon as a validating XML Parser.

The code I have looks like this:
try {
   System.setProperty("javax.xml.parsers.DocumentBuilderFactory","org.apache.xerces.jaxp.DocumentBuilderFactoryImpl");
   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
   Factory.setNamespaceAware(true);
   factory.setValidating(true);
   factory.setNamespaceAware(false);
   factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage","http://www.w3.org/2001/XMLSchema");
   factory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource",schema);
   DocumentBuilder builder = factory.newDocumentBuilder();
   Validator handler = new Validator();
   builder.setErrorHandler(handler);
   builder.parse(rawXML);
   if (handler.validationError == true) {
      System.out.println("XML Document has Error:" + handler.validationError + " " + handler.saxParseException.getMessage());
   }            
} catch (java.io.IOException ioe) {
   System.out.println("IOException " + ioe.getMessage());
}

The XML schema represented in the code above as the variable schema looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
      <xs:element name="ROW">
            <xs:complexType>
                  <xs:sequence>
                        <xs:element name="ZIP">
                              <xs:simpleType>
                                    <xs:restriction base="xs:int"/>
                              </xs:simpleType>
                        </xs:element>
                        <xs:element name="CITY">
                              <xs:simpleType>
                                    <xs:restriction base="xs:string"/>
                              </xs:simpleType>
                        </xs:element>
                        <xs:element name="COUNTRY">
                              <xs:simpleType>
                                    <xs:restriction base="xs:string">
                                          <xs:pattern value="[A-Z]{2}"/>
                                    </xs:restriction>
                              </xs:simpleType>
                        </xs:element>
                        <xs:element name="CITYCODE">
                              <xs:simpleType>
                                    <xs:restriction base="xs:string">
                                          <xs:pattern value="([A-Z]|[0-9]){3}"/>
                                    </xs:restriction>
                              </xs:simpleType>
                        </xs:element>
                        <xs:element name="ADDRESS">
                              <xs:simpleType>
                                    <xs:restriction base="xs:string"/>
                              </xs:simpleType>
                        </xs:element>
                        <xs:element name="BECODE">
                              <xs:simpleType>
                                    <xs:restriction base="xs:string">
                                          <xs:pattern value="[A-Z]{1}[0-9]{3}"/>
                                    </xs:restriction>
                              </xs:simpleType>
                        </xs:element>
                        <xs:element name="NAME">
                              <xs:simpleType>
                                    <xs:restriction base="xs:string"/>
                              </xs:simpleType>
                        </xs:element>
                  </xs:sequence>
            </xs:complexType>
      </xs:element>
</xs:schema>

And finally the XML I-m trying to validate looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<ROW>
  <ZIP>90660</ZIP>
  <CITY>Pico Rivera</CITY>
  <COUNTRY>US</COUNTRY>
  <CITYCODE>PIU</CITYCODE>
  <ADDRESS>NULL</ADDRESS>
  <BECODE>ABFS</BECODE>
  <NAME>ABF FREIGHT SYSTEM INC.</NAME>
</ROW>

When I run the code a MalformedURLException is thrown from the parse method above and the detailed message says:
no protocol: <?xml version="1.0" encoding="UTF-8"?>
<ROW>
  <ZIP>NULL</ZIP>
  <CITY>NULL</CITY>
  <COUNTRY>NULL</COUNTRY>
  <CITYCODE>NULL</CITYCODE>
  <ADDRESS>NULL</ADDRESS>
  <BECODE>AATW</BECODE>
  <NAME>AAA Trucking</NAME>
</ROW>

Has anyone got a clue as to what goes wrong here?

Regards
John
JohnBakAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
Make sure that all input entites have a protocol where a url is expected. E.g. suppose 'schema' holds the value myschema.xml and it's a file. That should be file:myschema.xml if in the current directory
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.