aspose file tools*
The moose likes XML and Related Technologies and the fly likes Dynamic Xml Parser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Dynamic Xml Parser" Watch "Dynamic Xml Parser" New topic
Author

Dynamic Xml Parser

Fawad Ali
Ranch Hand

Joined: Dec 28, 2009
Posts: 112
Hi Guys,
I am not new to Java but I have never used xml and xml parsing before. I need to convert an xml document to html page. I have xml in the following format



I want to iterate through the childNodes of Application node. I want to check whether the child nodes are simple nodes containing text only or complex nodes containing other child nodes. If it contains child nodes as the IntermediaryDetails is, I will have to iterate through that. The problem is that I want to iterate without knowing the names of the tags. I want to do it dynamically. Is there any parser which can parse it dynamically. I am sure there will be one. If you guys could provide ma a link to the tutorial of that parser, it will be great. And if you could paste a short snippet that will even greater. The algo will be like


Regards, Fawad Ali.
Software Engineer, Stafona Inc. - My Blog
Karthik Shiraly
Ranch Hand

Joined: Apr 04, 2009
Posts: 539
    
    7
Use TxAX (Transformation API for XML) and XSLT (XSL Transformations) for this.
The process is:
- write an XSLT. It contains rules for input file tags and what to output in output file when those rules are matched. You need to know XPath syntax because that's what helps in handling tags without knowing their names. For example, the xpath expression "/Application//EmailAddress" will return all nodes under <Application> at any depth whose tag is <EmailAddress>, and "/Application//*" returns all descendant nodes regardless of tag name. These rules go into the XSLT.

- Use the javax.xml.transform API to execute that XSLT on your input XML and produce output HTML. The XSLT takes in your XML input, uses the XPath expressions in that XSLT to match nodes in XML input, and outputs HTML.

Found a tutorial here
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12835
    
    5
Is there any parser which can parse it dynamically.


Actually all parsers are "dynamic" in the sense that they have NO preconceived notion about the input except that is in XML notation. As long as the XML is well formed, the parser will run.

What you do with the result is, of course, up to you. Perhaps you should read over some of the examples in Harold's free online book - you will probably find an example close to what you want to do.

Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Dynamic Xml Parser