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.

63 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
    Replies
    1. Big data is a term that describes the large volume of data – both structured and unstructured – that inundates a business on a day-to-day basis. big data projects for students But it’s not the amount of data that’s important. Project Center in Chennai It’s what organizations do with the data that matters. Big data can be analyzed for insights that lead to better decisions and strategic business moves.

      Spring Framework has already made serious inroads as an integrated technology stack for building user-facing applications. Corporate TRaining Spring Framework the authors explore the idea of using Java in Big Data platforms.
      Specifically, Spring Framework provides various tasks are geared around preparing data for further analysis and visualization. Spring Training in Chennai


      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

      Delete
  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. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. Nice post. I learned some new information. Thanks for sharing.

    chocolatesanddreams
    Guest posting sites

    ReplyDelete
  22. 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
  23. Amazing blog about the various informative information on the programming languages... Java Training in Chennai | Pega Training in Chennai

    ReplyDelete
  24. 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
  25. I am happy to find this post Very useful for me, as it contains lot of information

    Education
    Technology

    ReplyDelete
  26. 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

  27. 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
  28. 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
  29. Когда человек задает вопрос где купить лед ленту я всегда отвечаю в ekodio, супер качество и супер цены.

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

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

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

    ReplyDelete