Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-06-2008, 04:47 PM
Member
 
Join Date: May 2008
Posts: 12
palanikumark is on a distinguished road
Send a message via Skype™ to palanikumark
Extract xml to store into db
Hi all,

I need to get the data from the xml file and store it onto the database. Is there anyway of doing this?

thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-06-2008, 04:48 PM
pao pao is offline
Member
 
Join Date: Jun 2008
Posts: 41
pao is on a distinguished road
You can do this using SAX or DOM and parse the xml file. You can write Xpath queries to get parts that you require using DOM? I cant quite remember but I have used both methods in the past.

Let me know if you need anymore help.

Cheers

Last edited by pao : 06-06-2008 at 04:50 PM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-06-2008, 05:01 PM
Member
 
Join Date: May 2008
Posts: 12
palanikumark is on a distinguished road
Send a message via Skype™ to palanikumark
Can u give example...?

Thanks
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-06-2008, 05:09 PM
pao pao is offline
Member
 
Join Date: Jun 2008
Posts: 41
pao is on a distinguished road
Ok here is a small example, you will need to pick through the method and get the bits you want out. I have also removed some parts as it is sensitive to my employment role... But it shouldnt be anything of any importance but this method may not compile now, it will probably just be a bracket missing or something. Good luck! ps this is using DOM:

Code:
//Class imports YOU may not need all of these import javax.xml.xpath.*; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; import javax.xml.parsers.*; import javax.xml.namespace.*; import org.w3c.dom.*; import org.xml.sax.*; import javax.xml.messaging.URLEndpoint; public static org.w3c.dom.Node getPayload(String xPath, String xml, String nodeName) throws Exception { //Create a new XPath object and add a namespace context reference to the //XPath object that allows the XPath to map the prefix to a namespace XPath xpath = XMLUtilities.getXPath(new MyContext()); //System.out.println(xml); //Perform the transform DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder db = factory.newDocumentBuilder(); Document document = db.parse(new InputSource(new StringReader(xml))); //Obtain the part of the SOAP message that we are interested in as //a org.w3c.dom.Node object. org.w3c.dom.Node titleNode = (org.w3c.dom.Node) xpath.evaluate(xPath, document, XPathConstants.NODE); NodeList nodeList = titleNode.getChildNodes(); org.w3c.dom.Node tempNode = null; org.w3c.dom.Node payLoad = null; org.w3c.dom.Node controlActEventNode = null; org.w3c.dom.Node reasonNode = null; for(int i = 0; i < nodeList.getLength(); i++) { tempNode = nodeList.item(i); if(tempNode.getNodeName().equals(nodeName)) { payLoad = nodeList.item(i); } else if (tempNode.getNodeName().equals("Node I want")) { //New changes to the message mean we can no longer rely on org.w3c.dom.NodeList reasonNodes = (NodeList) xpath.evaluate(XPathQueryConstants.PROCESS_ERROR_RESPONSE, tempNode, XPathConstants.NODESET); for(int j = 1; j <= reasonNodes.getLength(); j++) { reasonNode = reasonNodes.item(j - 1); reasonCode = (String)xpath.evaluate("//prefix:reason[" + j + "]/prefix:justifyingDetectedIssueEvent/prefix:code/@code", reasonNode, XPathConstants.STRING); if(reasonCode.length() == 5) { reasonString = (String)xpath.evaluate("//prefix:reason[" + j + "]/prefix:justifyingDetectedIssueEvent/prefix:code/@displayName", reasonNode, XPathConstants.STRING); } } return payLoad; }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Extract Interface (II) JavaForums Java Blogs 0 03-12-2008 05:00 PM
Extract Interface (I) JavaForums Java Blogs 0 03-12-2008 12:40 AM
Extract superclass(II) JavaForums Java Blogs 0 03-12-2008 12:40 AM
Extract superclass(I) JavaForums Java Blogs 0 03-12-2008 12:40 AM
How to extract information from a sentece luisarca Sun Java Wireless Toolkit 1 12-03-2007 01:34 PM


All times are GMT +3. The time now is 12:50 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org