aspose file tools*
The moose likes Web Services and the fly likes Load xml string into DOM ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Load xml string into DOM ?" Watch "Load xml string into DOM ?" New topic
Author

Load xml string into DOM ?

Nathan Russell
Ranch Hand

Joined: Aug 18, 2004
Posts: 75
Hi,
I wonder if anyone can help.
I have written an application that communicates with a webservice over REST; reads the resultant string (which is the xml document) into an xml dom object, parses and processes it.
No problems; except its currently written in VB, and now I want to port it to Java.
I've written the code to make the http request to the webservice; and I get the result in a String object. Now I want to load it into the dom and process it.

I'm using IBM's XML4J.jar; and I have the following code:


Here's where I get stuck ! The only method I can find any reference to is parse which appears to take a parameter of a filename, which then reads the contents of the file.
Not quite what I want ! I already have my xml in a String object, I just want to pass it into the parser.
In my VB code, at this point I use a method called loadXML and pass the string, but I cant find a similar object here !!

Any help with this would be very much appreciated !
Thanks

Nathan
JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
Does this code help ??



Could you also explain to us why you chose a REST implementation and not a SOAP one.
It's interesting...


/ JeanLouis<br /><i>"software development has been, is, and will remain fundamentally hard" (Grady Booch)</i><br /> <br />Take a look at <a href="http://www.epfwiki.net/wikis/openup/" target="_blank" rel="nofollow">Agile OpenUP</a> in the Eclipse community
Nathan Russell
Ranch Hand

Joined: Aug 18, 2004
Posts: 75
JeanLouis,

Thanks for your suggestions - they sound promising, except I cant get it to compile !!
Basically, the compiler tells me it cant resolve the type InputSource - what import should I use for this ? It doesn't appear to be in java.io or java.util

Why am I using REST ?
Cos it seems easiest ! The webservices I am using (amazon) provide for both SOAP and REST - but being a bit of a novice (can you tell !!), I decided that REST was easier as there was more documentation and examples !

Thanks

Nathan
Nathan Russell
Ranch Hand

Joined: Aug 18, 2004
Posts: 75
OK, found the answer .... InputSource can be found in org.xml.sax
Seems to work OK for me !, and yes, JeanLouis, your suggestion as a whole is workin brilliantly ! Thanks

Now just to work out the differences between the java and ms methods !!!

How about this for starters ?
With the MS method getElementsByTagName, I can specify a branch of the tree by using the / as a delimiter (eg. getElementsByTagName("Items/Item") )
The java version (or at least the one in IBMs XML4J) does not seem to like this. It accepts it and the code compiles, but it finds nothing !
Anyone know what the delimiter character is ?

Cheers

Nathan
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by Nathan Russell:
How about this for starters ?
With the MS method getElementsByTagName, I can specify a branch of the tree by using the / as a delimiter (eg. getElementsByTagName("Items/Item") )
The java version (or at least the one in IBMs XML4J) does not seem to like this. It accepts it and the code compiles, but it finds nothing !
Anyone know what the delimiter character is ?
Cheers
Nathan

Nathan, You may get a better chances of reply if you post this particular question in "Xml and other technologies" forum of javaranch. (as you did for the other post).


Spritle Software Blogs
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Load xml string into DOM ?