• 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

Dynamic Xml Parser

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1210
25
Android Python PHP C++ Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic