Friday, September 13, 2013

Convert XML String to OMElement and extract values

A simple tip which saves a lot of your time...
You can simply convert XML string to an OMElement as below

      OMElement resultElement = AXIOMUtil.stringToOM(xmlString);


Extracting values from XML


Sample XML code


        Gambardella, Matthew
        XML Developer's Guide
        Computer
        44.95
        2000-10-01
        An in-depth look at creating applicationswith XML.
    
    
        Ralls, Kim
        Midnight Rain
        Fantasy
        5.95
        2000-12-16
        A former architect battles corporate zombies,an evil sorceress.
    
    
        Corets, Eva
        Maeve Ascendant
        Fantasy
        5.95
        2000-11-17
        After the collapse of a nanotechnologysociety in England.
    
    
        Corets, Eva
        Oberon's Legacy
        Fantasy
        5.95
        2001-03-10
        In post-apocalypse England, the mysteriousagent known only as Oberon.
    


Java code to retrieve values


OMElement resultElement = AXIOMUtil.stringToOM(xmlString);

        Iterator i = resultElement.getChildren();
        while (i.hasNext()) {
            OMElement book = (OMElement) i.next();
            Iterator properties = book.getChildren();
            System.out.println("====== book =======");
            while (properties.hasNext()) {
                OMElement property = (OMElement) properties.next();
                String localName = property.getLocalName();
                String value = property.getText();
                System.out.println(localName + ": " + value);
            }
        }


Result

====== book =======
author: Gambardella, Matthew
title: XML Developer's Guide
genre: Computer
price: 44.95
publish_date: 2000-10-01
description: An in-depth look at creating applicationswith XML.
====== book =======
author: Ralls, Kim
title: Midnight Rain
genre: Fantasy
price: 5.95
publish_date: 2000-12-16
description: A former architect battles corporate zombies,an evil sorceress.
====== book =======
author: Corets, Eva
title: Maeve Ascendant
genre: Fantasy
price: 5.95
publish_date: 2000-11-17
description: After the collapse of a nanotechnologysociety in England.
====== book =======
author: Corets, Eva
title: Oberon's Legacy
genre: Fantasy
price: 5.95
publish_date: 2001-03-10
description: In post-apocalypse England, the mysteriousagent known only as Oberon.

41 comments:

  1. There are lots of information about latest technology, like Hadoop cluster is a special type of computational cluster designed specifically for storing and analyzing huge amounts of unstructured data in a distributed computing environment. This information seems to be more unique and interesting. Thanks for sharing.
    Hadoop Training in Chennai | Hadoop Training Chennai | Hadoop Training in Chennai

    ReplyDelete
  2. There is a huge demand for professional big data analysts who are able to use the software which is used to process the big data in order to get accurate results. MNC's are looking for professionals who can process their data so that they can get into a accurate business decision which would eventually help them to earn more profits, they can serve their customers better, and their risk is lowered.
    big data training in chennai|big data training|big data course in chennai|big data training chennai

    ReplyDelete
  3. Big data is used extensively in MNC today as using big data leads to accurate decision making and there are is a huge demand for the big data analysts.
    Big data training in Chennai | Hadoop training in Chennai | Big data training institute in Chennai

    ReplyDelete
  4. The greatest question of most engineers i experience is this: this a decent time to learn streak? is it to late to join the gathering? Is the following party going to be in glimmer or an alternate dialect is quickly coming to assume control (JavaScript?HTML5?)? java programming

    ReplyDelete
  5. I have read your blog its very attractive and impressive. I like it your blog.
    Java Training in Chennai

    ReplyDelete
  6. You are doing a great job. You inspire me to write for other. Thank you very much. I would like to appreciate your work for good accuracy and got informative knowledge from here
    Java Training in Chennai

    ReplyDelete
  7. I have read your blog its very attractive and impressive. I like it your blog. Thanks for sharing.keep sharing more blog. wanyt to build your own websites

    White Label Website Builder

    ReplyDelete
  8. hi admin.i am really love it your blog.Because your explanation wise all the topics are too good.I got enough knowledge from your blog.Thanks for sharing more..
    Java Training in Marathahalli
    Python Training in Marathahalli

    ReplyDelete
  9. There are lots of information about hadoop have spread around the web, but this is a unique one according to me. The strategy you have updated here will make me to get to the next level in big data. Thanks for sharing this. Java Training in Chennai | Data Science Training in Chennai

    ReplyDelete
  10. Hi, you have given really informative post. Thanks for sharing this post to our vision. Learn Java will helps you to reach your goal.Java Training in Marathahalli
    Data Science Training in BTM Layout

    ReplyDelete
  11. Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

    Java Training in Chennai

    Java Training in Bangalore

    ReplyDelete
  12. Thanks for splitting your comprehension with us. It’s really useful to me & I hope it helps the people who in need of this vital information.
    Android Training in Chennai

    ReplyDelete
  13. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

    Best Java Training Institute Chennai

    Java Training Institute Bangalore

    ReplyDelete
  14. I believe there are many more pleasurable opportunities ahead for individuals that looked at your site. RPA Training in Chennai | Blue Prism Training in Chennai

    ReplyDelete

  15. I have read your blog and I gathered some needful information from your blog. Keep update your blog. Java Training in Chennai | Pega Training in Chennai

    ReplyDelete
  16. Great Article… I love to read your articles because your writing style is too good, its is very very helpful for all of us. Do check | Get trained by an expert who will enrich you with the latest updates.
    Web Designing Course in chennai
    web designing training in chennai
    Web Development courses in Chennai
    Java Training in Chennai
    Java course in Chennai
    Java Training Institute in Chennai

    ReplyDelete
  17. I would like to thank you much about this great post. Its very useful and helpful for anyone looking for tips to help him learn and master in Angularjs. I like your writing style and I hope you will keep doing this good working.
    Angularjs Coaching in Bangalore
    Angularjs Institute in Bangalore
    Best Angularjs Training in Bangalore
    Best Android Training in Bangalore
    Android Developer Course in Bangalore
    Android App Development Training in Bangalore

    ReplyDelete
  18. I am really enjoying reading your well written articles.
    It looks like you spend a lot of effort and time on your blog.
    I have bookmarked it and I am looking forward to reading new articles. Keep up the good work..
    Java Training in Bangalore
    Best Java Training Institutes in Bangalore
    Java Course in Bangalore
    best big data training in bangalore
    hadoop classes in bangalore
    hadoop institute in bangalore

    ReplyDelete
  19. Nice post. I learned some new information. Thanks for sharing.

    chocolatesanddreams
    Guest posting sites

    ReplyDelete
  20. I am happy to find this post Very useful for me, as it contains lot of information

    Education
    Technology

    ReplyDelete

  21. You are doing a great job. I would like to appreciate your work for good accuracy
    Regards,
    PHP Training in Chennai | PHP Course in Chennai

    ReplyDelete
  22. This comment has been removed by the author.

    ReplyDelete
  23. Super site! I am Loving it!! Will return once more, Im taking your food additionally, Thanks. Convert 170 lbs to kg

    ReplyDelete
  24. Maintaining: The Science maintains the processed data using data warehousing, data cleansing, data staging, and data architecture. data science course syllabus

    ReplyDelete