Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By gimbal2

Thread: how to remove unwanted tags from xml

  1. #1
    abhi140291 is offline Member
    Join Date
    Nov 2013
    Posts
    9
    Rep Power
    0

    Default how to remove unwanted tags from xml

    <BankDetails>
    <Country>
    <CountryName>Afghanistan</CountryName>
    <CountryCode>AF</CountryCode>
    <BankName>Afghanistan International Bank</BankName>
    <Website>http://www.aib.af/</Website>
    <CustomerCare>93202550255</CustomerCare>
    </Country>
    <Country>
    <CountryName>Afghanistan</CountryName>
    <CountryCode>AF</CountryCode>
    <BankName>Afghan United Bank</BankName>
    <Website>http://www.afghanunitedbank.com/</Website>
    <Name>Account balance</Name>
    <SMS>BAL</SMS>
    <SMSNumber>3838</SMSNumber>
    <CustomerCare>93202203838</CustomerCare>
    </Country>



    i want to remove country Tags from above xml file please suggest me the way

  2. #2
    SurfMan's Avatar
    SurfMan is online now Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    946
    Rep Power
    2

    Default Re: how to remove unwanted tags from xml

    Nothing special about this case. It's either DOM or SAX, usually depending on the size of the XML document. Plenty of examples around on teh Interwebs.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  3. #3
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,989
    Rep Power
    5

    Default Re: how to remove unwanted tags from xml

    I'd probably use JAXB to map the XML to an object to be honest, if it is really this small. Then using the @XmlTransient annotation you can mark which fields you want to ignore when marshalling/unmarshalling the object.
    PinkRose likes this.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    SurfMan's Avatar
    SurfMan is online now Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    946
    Rep Power
    2

    Default Re: how to remove unwanted tags from xml

    I must admit I never have looked at the latest JAXB, and while reading this article of Lars Vogel, I might be temped to play with it. With my default set of utility classes I write an XML document parsing solution in seconds, but I like the JAXB idea.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  5. #5
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,989
    Rep Power
    5

    Default Re: how to remove unwanted tags from xml

    Usually you use JAXB by extension as part of another API/framework :) I got introduced to it through JAX-WS and JAX-RS, and especially how it is used in JAX-RS made me very partial to it. It can be as simple as slapping a single annotation on a class to make it fully XML serializable/deserializable; many JSON APIs make it possible to leverage JAXB to work with JSON data in stead with the exact same objects and annotations.

    EDIT: and as an additional sales pitch, it is also one of the better documented APIs out there:

    https://jaxb.java.net/2.2.7/docs/
    Last edited by gimbal2; 11-26-2013 at 10:14 AM.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

Similar Threads

  1. Unwanted Null output.
    By steinarsen in forum New To Java
    Replies: 8
    Last Post: 11-08-2012, 10:01 AM
  2. Unwanted image fragment
    By polmos in forum New To Java
    Replies: 6
    Last Post: 09-12-2012, 03:00 PM
  3. How to remove all html tags within my <H1> tag
    By masterrs.mind in forum Advanced Java
    Replies: 3
    Last Post: 03-17-2010, 02:32 AM
  4. unwanted bug. JMenu
    By ocean in forum New To Java
    Replies: 7
    Last Post: 11-20-2009, 09:29 PM
  5. Repositioning An unwanted JInternalFrame
    By marco.c84 in forum AWT / Swing
    Replies: 8
    Last Post: 03-18-2009, 09:42 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •