Uploaded image for project: 'Xerces2-J'
  1. Xerces2-J
  2. XERCESJ-1359

DOMParser exception with an xml file which name contains Chinese characters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Minor
    • Resolution: Duplicate
    • 2.9.1
    • None
    • None
    • Windows in China

    Description

      Under the same directory, there are an xml file a.xml and a schema file r.xsd.

      With the code below, all is ok. But if change the name of the file a.xml to a name containing Chinese characters (eg 中.xml), then the DOMParser issues an Exception:
      java.net.MalformedURLException: unknown protocol: e
      at java.net.URL.<init>(URL.java:586)
      at java.net.URL.<init>(URL.java:476)
      at java.net.URL.<init>(URL.java:425)
      at org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
      at org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
      at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
      at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
      at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
      at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
      at xml.DOMParserDemo.main(DOMParserDemo.java:36)

      And if replace parser.parse("E:/a.xml"); with parser.parse("file:E:/中.xml"); then it gives some warnings and errors:
      [Warning] 中.xml:3:117: schema_reference.4: Failed to read schema document 'r.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
      [Error] 中.xml:3:117: cvc-elt.1: Cannot find the declaration of element 'ResourceReg'.
      [Warning] 中.xml:5:16: schema_reference.4: Failed to read schema document 'r.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
      [Warning] 中.xml:8:18: schema_reference.4: Failed to read schema document 'r.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
      [Warning] 中.xml:10:15: schema_reference.4: Failed to read schema document 'r.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
      [Warning] 中.xml:12:18: schema_reference.4: Failed to read schema document 'r.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
      [Warning] 中.xml:18:19: schema_reference.4: Failed to read schema document 'r.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
      [Warning] 中.xml:20:11: schema_reference.4: Failed to read schema document 'r.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
      [Warning] 中.xml:22:11: schema_reference.4: Failed to read schema document 'r.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
      [Warning] 中.xml:24:11: schema_reference.4: Failed to read schema document 'r.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
      [Warning] 中.xml:26:10: schema_reference.4: Failed to read schema document 'r.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.

      the code:
      try

      { DOMParser parser = new DOMParser(); parser.setFeature("http://xml.org/sax/features/validation",true); parser.setFeature("http://apache.org/xml/features/validation/schema",true); parser.parse("E:/a.xml"); Document doc = parser.getDocument(); }

      catch(Exception e)

      { e.printStackTrace(); }

      a.xml:
      <?xml version="1.0" encoding="gb2312"?>
      <ResourceReg xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNameSpaceSchemaLocation="r.xsd">
      <ResourceFig>
      <ResourceKID>512 </ResourceKID>
      <PortAddr>192.192.192.222:1:1 </PortAddr>
      <ResourceSID>3 </ResourceSID>
      </ResourceFig>
      <ResourceStatus>
      <ZBWZ>135,26 </ZBWZ>
      <YXZT>1 </YXZT>
      <CSQB>true </CSQB>
      <BKF>2 </BKF>
      </ResourceStatus>
      </ResourceReg>

      r.xsd:
      <?xml version="1.0"?>
      <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="ResourceReg">
      <xs:complexType>
      <xs:all>
      <xs:element name="ResourceFig" type="ResourceFig" minOccurs="1" maxOccurs="1" />
      <xs:element name="ResourceStatus" minOccurs="1" maxOccurs="1" />
      </xs:all>
      </xs:complexType>
      </xs:element>
      <xs:complexType name="ResourceFig">
      <xs:all>
      <xs:element name="ResourceKID" type="xs:unsignedShort" />
      <xs:element name="PortAddr" type="xs:token" />
      <xs:element name="ResourceSID" type="xs:unsignedByte" />
      </xs:all>
      </xs:complexType>
      </xs:schema>

      Attachments

        Activity

          People

            Unassigned Unassigned
            liaomingxue liaomingxue
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: