This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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
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.