jira.codehaus.org

  • Log In Access more options
    • Online Help
    • Keyboard Shortcuts
    • About JIRA
    • JIRA Credits
    • What?s New
  • Dashboards Access more options (Alt+d)
  • Projects Access more options (Alt+p)
  • Issues Access more options (Alt+i)
Signup
XStream
  • XStream
  • XSTR-334

fromXML(URL)

  • Log In
  • Views
    • XML
    • Word
    • Printable

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 1.4
  • Component/s: None
  • Labels:
    None
  • JDK version and platform:
    Apple JDK 1.5.0_06, Mac OS 10.4.6 (PPC)

Description

I have a number of XStream serialised files which have been hand edited to refer to a DTD containing entity declarations to encapsulate data (file paths in my case) which is shared between the files.

If I try to use the XStream.fromXML methods to load these files it fails, as the parser does not have the system ID of the XML file and so is unable to locate the DTD. It would be nice if XStream provided a fromXML(URL) method that passes the system ID to the parser, as the workaround involves explicitly creating e.g. an XMLStreamReader and StaxReader to pass to XStream.unmarshal, which ties the code to one particular driver.

Activity

Ascending order - Click to sort in descending order
  • All
  • Comments
  • History
  • Activity
Hide
Permalink
Fran Martin added a comment - 28/Mar/08 4:26 AM

Hello,

I have the same problem. I thought the solution would be adding a XStream.fromXML(File), but maybe the XStream.fromXML(URL) that Ian suggests is more ellegant. I would vote for both, anyway.

I use XML files like this:

sample.xml
-----------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE person SYSTEM "sample.dtd" [
<!ENTITY p SYSTEM "person.xml">
]>
<person>
&p;
</person>
-----------------------------------------------------------------------

This file references an external DTD (sample.dtd) and an included XML (person.xml).

When you parse from InputStream or Reader, using XStream or directly a DocumentBuilder, referenced files (sample.dtd and person.xml) are not searched in the same folder as sample.xml, as it could be expected. I think they are searched in the classpath.

On the other hand, if you parse sample.xml using DocumentBuilder.parse(File) method, it looks for referenced files in the same folder.

If there was a XStream.fromXml(File) method, I could use it directly:

Person person = (Person) xstream.fromXml( new File("sample.xml") );

But, since it doesn't exist, I'm forced to do this:

Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( new File("sample.xml") );
Person person = (Person) xstream.unmarshal( new DomReader(doc) );

Regards,
ranMa

Show
Fran Martin added a comment - 28/Mar/08 4:26 AM Hello, I have the same problem. I thought the solution would be adding a XStream.fromXML(File), but maybe the XStream.fromXML(URL) that Ian suggests is more ellegant. I would vote for both, anyway. I use XML files like this: sample.xml ----------------------------------------------------------------------- <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE person SYSTEM "sample.dtd" [ <!ENTITY p SYSTEM "person.xml"> ]> <person> &p; </person> ----------------------------------------------------------------------- This file references an external DTD (sample.dtd) and an included XML (person.xml). When you parse from InputStream or Reader, using XStream or directly a DocumentBuilder, referenced files (sample.dtd and person.xml) are not searched in the same folder as sample.xml, as it could be expected. I think they are searched in the classpath. On the other hand, if you parse sample.xml using DocumentBuilder.parse(File) method, it looks for referenced files in the same folder. If there was a XStream.fromXml(File) method, I could use it directly: Person person = (Person) xstream.fromXml( new File("sample.xml") ); But, since it doesn't exist, I'm forced to do this: Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse( new File("sample.xml") ); Person person = (Person) xstream.unmarshal( new DomReader(doc) ); Regards, ranMa
Hide
Permalink
Magnus Melin added a comment - 14/Jul/09 7:29 AM

Any update? This is really annoying!

Show
Magnus Melin added a comment - 14/Jul/09 7:29 AM Any update? This is really annoying!
Hide
Permalink
Jörg Schaible added a comment - 14/Jul/09 9:33 AM

@Magnus: This is open source and committers spend there free time. If it is your itch, provide a patch and unit tests! Otherwise wait.

Show
Jörg Schaible added a comment - 14/Jul/09 9:33 AM @Magnus: This is open source and committers spend there free time. If it is your itch, provide a patch and unit tests! Otherwise wait.
Hide
Permalink
Jörg Schaible added a comment - 03/Aug/11 5:09 PM

Added both variants. Some parsers will take advantage of these objects for the SystemId. Available in HEAD.

Show
Jörg Schaible added a comment - 03/Aug/11 5:09 PM Added both variants. Some parsers will take advantage of these objects for the SystemId. Available in HEAD.

People

  • Assignee:
    Jörg Schaible
    Reporter:
    Ian Roberts
Vote (2)
Watch (1)

Dates

  • Created:
    22/Aug/06 7:54 AM
    Updated:
    05/Aug/11 5:04 PM
    Resolved:
    03/Aug/11 5:09 PM
  • Atlassian JIRA (v5.2.7#850-sha1:b2af0c8)
  • Report a problem
  • Powered by a free Atlassian JIRA open source license for Codehaus. Try JIRA - bug tracking software for your team.