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.

62 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. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    salesforce training in chennai | salesforce training institute in chennai

    ReplyDelete
  5. Hibernate Online Training Hibernate Online Training Hibernate Training in Chennai Hibernate Training in Chennai Java Online Training Java Online Training

    Hibernate Training Institutes in ChennaiHibernate Training Institutes in Chennai Java Online Training Java Online Training Java Online Training Java Online Training

    ReplyDelete
  6. 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
  7. I have read your blog its very attractive and impressive. I like it your blog.
    Java Training in Chennai

    ReplyDelete
  8. 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
  9. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  10. 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
  11. 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
  12. 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
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. This information is impressive; I am inspired by your post writing style & how continuously you describe this topic.... Java Training in Chennai | Python Training in Chennai

    ReplyDelete
  19. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it... Java Training in Chennai | RPA Training in Chennai

    ReplyDelete

  20. 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

  21. 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
  22. Your very own commitment to getting the message throughout came to be rather powerful and have consistently enabled employees just like me to arrive at their desired goals.
    safety course in chennai

    ReplyDelete
  23. 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
  24. 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
  25. 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
  26. Nice post. I learned some new information. Thanks for sharing.

    chocolatesanddreams
    Guest posting sites

    ReplyDelete
  27. Great job.... Awesome list, just starting a blog and this is going to be a massive help. Thank you!

    Cloud Training
    Software Testing Training
    Oracle DBA Training
    Angular Training in Chennai

    ReplyDelete
  28. Amazing blog about the various informative information on the programming languages... Java Training in Chennai | Pega Training in Chennai

    ReplyDelete
  29. Thanks for sharing this unique information with us. Your post is really awesome. Your blog is really helpful for me..
    Top college in Jaipur|law college|law college in Jaipur|Best law college in Jaipur

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

    Education
    Technology

    ReplyDelete
  31. I wish to indicate because of you only to bail me out of this specific trouble. As a consequence of checking through the net and meeting systems that were not beneficial, I thought my life was finished.
    iosh safety course in chennai

    ReplyDelete
  32. You can find the best casino here all online casinos are good Big win is waiting for you.

    ReplyDelete

  33. 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
  34. Amazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live. I have bookmarked more article from this website. Such a nice blog you are providing ! Kindly Visit Us @ Best Travels in Madurai | Tours and Travels in Madurai | Madurai Travels

    ReplyDelete
  35. Когда человек задает вопрос где купить лед ленту я всегда отвечаю в ekodio, супер качество и супер цены.

    ReplyDelete