• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Jaxp parsing problem

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I'm using jaxp for parsing and validating (xml schema) a xml file.

This is what I do...
==================================

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
dbf.setValidating( true );
try{
dbf.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
} catch (Exception e) {
e.printStackTrace(System.err);
}

DocumentBuilder db = dbf.newDocumentBuilder();
OutputStreamWriter errorWriter =
new OutputStreamWriter(System.err, outputEncoding);

db.setErrorHandler(
new SimpleErrorHandler(
new PrintWriter(errorWriter, true)
)
);

try{

Document document =
db.parse( new File( "src/xml/sudoku01.xml" ));
}
catch( SAXException se ){
System.err.println(se.getMessage());
}

==================================

All works right, the xml file is loaded, parsed and validated right.

But now I need to parse an InputStream, not directly a File object.
But if I simply change the File object with a stream the parser stop validating telling me that the xml file don't have good elements.

Change applied to precedent code....
==================================
try{
InputStream ist = new FileInputStream(
new File("src/xml/sudoku01.xml")
);

Document document =
db.parse( ist );

}
==================================


Where is my fault in using InputStream rather than directly a File object?

Hope anyone can help me
[ June 03, 2008: Message edited by: f. taioli ]
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"fbn tla",
Please check your private messages regarding an important administrative matter.
-Ben
 
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Perhaps your XML document has a relative URI saying where its schema is located. In this case the parser knows where a File is located so it can find the schema relative to the file. But the parser doesn't know where an InputStream got its data from so it can't find the schema relative to that.
 
f. taioli
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Clapham:
Perhaps your XML document has a relative URI saying where its schema is located. In this case the parser knows where a File is located so it can find the schema relative to the file. But the parser doesn't know where an InputStream got its data from so it can't find the schema relative to that.



Thank you for your reply but my xml documet hav an absolute url for the schema... I think.

This is my xml file intestation (http://twi.loc is a working local web server )

<?xml version="1.0" encoding="UTF-8"?>
<sudoku xmlns="http://twi.loc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://twi.loc sudoku.xsd"
sid="473" >
 
Paul Clapham
Marshal
Posts: 28226
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"sudoku.xsd" certainly looks like a relative URI to me. I don't know much about schemas but when I read the XML Schema recommendation, it looks to me likemeans "You can find the schema definition for namespace http://twi.loc at the URI sudoku.xsd". And if this is the case, http://twi.loc isn't where the parser will look for the schema definition. The parser will look for it in sudoku.xsd.

In general a namespace URI is just a name. It doesn't have to be the URL of an actual page on the web. I don't think XML Schema changes that in any way.
[ June 07, 2008: Message edited by: Paul Clapham ]
 
f. taioli
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Opss... you are right thank you very mutch
 
Do not threaten THIS beaver! Not even with this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic