Jump to content

Recommended Posts

I have a doubt about the use of JDOM parsing a xml document. The outcome is not what I expect..I did the next program to parse a xml document. I have considered that the root of the document id the element bodyimport org.jdom.*;import org.jdom.input.SAXBuilder;import org.jdom.output.*;import java.io.File;import java.io.IOException;import java.util.*;public class Ex04 { public static void main(String[] args) { String filename = "Test.xml"; SAXBuilder b = new SAXBuilder(); try { Document doc = b.build(new File(filename)); Element root = doc.getRootElement(); Element body = root.getChild("body"); bodyExtract(body); } // indicates a well-formedness error catch (JDOMException e) { System.out.println(args[0] + " is not well-formed."); System.out.println(e.getMessage()); } catch (IOException e) { System.out.println(e); } } public static void bodyExtract(Element current) { String aaa = current.getText(); List children = current.getChildren(); Iterator iterator = children.iterator(); while (iterator.hasNext()) { Element child = (Element) iterator.next(); bodyExtract(child); } }}#######################################################################Part of the original Test.xml file is:...<body> The <a href=" http://www.linux.org/">Linux</a> is na open-source operating system, created by <a href=" http://technorati.com/tag/linus-torvals">Linus Torvalds</a> in the 80’s. ...The output of the program above is:The is an open-source operating system, created by in the 80’s. LinuxLinus TorvaldsI want to analyze semantically the sentences. Thus I need that the output is something like this:The Linux is an open-source operating system, created by Linus Torvaldsin the 80’s. How can I solve this problem,Thanx for your helpMP

Link to post
Share on other sites

I don't know about JDOM, but to embed html in xml you have to take special action or the xml is not well-formed. Your solution probably involves the use of CDATA and/or replacing "<" and ">"; please do a quick search about this to understand the issue and decide on a strategy that suits your JDOM world. For instance see:http://biglist.com/lists/lists.mulberrytec...8/msg00144.htmlgoogle

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...