Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

When I try to parse an XML file wit

Status
Not open for further replies.

MikoKitty

Programmer
Jul 22, 2003
5
CA
When I try to parse an XML file with a # in the filename, (e.g. C@#Test#1MB.xml), I get the following error:
java.net.MalformedURLException: unknown protocol: c
at java.net.URL.<init>(URL.java:507)
at java.net.URL.<init>(URL.java:403)
at java.net.URL.<init>(URL.java:357)
at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)

I tried using &quot;file:///C@#Test#1MB.xml&quot; but it doesn't recognize any characters after the first # and instead I get the following error:

java.io.FileNotFoundException: C:\C@(The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:78)
at sun.net. at sun.net. at java.net.URL.openStream(URL.java:825)
at org.apache.xerces.impl.XMLEntityManager.startEntity(Unknown Source)
at org.apache.xerces.impl.XMLEntityManager.startDocumentEntity(Unknown Source)
at org.apache.xerces.impl.XMLDocumentScannerImpl.setInputSource(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
at com.cds.scribe.test.Test.main(Test.java:35)

Is there some way to parse an XML file with a # character in it?
 
Hey!

try wrapping it in an input source:

Code:
{
SAXParserFactory spf = SAXParserFactory.newInstance();

spf.setNamespaceAware(true);

XMLReader reader = spf.newSAXParser().getXMLReader();

reader.setFeature(&quot;[URL unfurl="true"]http://xml.org/sax/features/namespace-prefixes&quot;,[/URL] true);

reader.setContentHandler(new Namespace());

String path = File.separatorChar+&quot;projects&quot;+File.separatorChar;

org.xml.sax.InputSource is = new InputSource();

is.setCharacterStream(new FileReader(path+&quot;test#file.txt&quot;));

Code:
reader.parse(is);
}

Jeff
 
Hi Jeff, thank you for the tip! It worked fine.

Regards,
Kathy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top