RemoveChild and BlankSpace in the XML file.

Discussion in 'Java' started by Achille, Nov 22, 2004.

  1. Achille

    Achille Guest

    Hi all,
    I need to remove a node in my XML file.
    I use the DOMParser.

    If I use the removeChild, the node is removed but a white line remains
    in my Dom tree and file xml.

    How do I also do to remove the blanck line?

    Thanks!
    By
    Achille
     
    Achille, Nov 22, 2004
    #1
    1. Advertisements

  2. Achille wrote:

    > Hi all,
    > I need to remove a node in my XML file.
    > I use the DOMParser.
    >
    > If I use the removeChild, the node is removed but a white line remains
    > in my Dom tree and file xml.
    >
    > How do I also do to remove the blanck line?
    >
    > Thanks!
    > By
    > Achille

    if the parser has not been set in a validating mode
    (DocumentBuilderFactory.isValidating{}) It's connected by that spaces or
    line carring between anyone two consecutive elements of DOM are treated
    as a TextNode.
    There is only one way to avoid it is it to set a validating mode and set
    a ignoring whitespaces.
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setValidating(true);
    factory.setIgnoringElementContentWhitespace(true);
    builder = factory.newDocumentBuilder();
    ....

    Anyway If you know document structure You can remove nasty text nodes
    itself.

    --
    Alex
     
    Alexey Dmitriev, Nov 22, 2004
    #2
    1. Advertisements

  3. Achille

    suma1810

    Joined:
    Oct 24, 2015
    Messages:
    2
    Likes Received:
    0
    I am getting an error after modifying the code like above n its not removing blank line

    Warning: validation was turned on but an org.xml.sax.ErrorHandler was not
    set, which is probably not what is desired. Parser will use a default
    ErrorHandler to print the first 10 errors. Please call
    the 'setErrorHandler' method to fix this..
     
    suma1810, Oct 24, 2015
    #3
  4. Achille

    suma1810

    Joined:
    Oct 24, 2015
    Messages:
    2
    Likes Received:
    0
    I have done like below
    dBuilder.setErrorHandler(null);
    now I am not getting error but its not removing blank line in xml
     
    suma1810, Oct 24, 2015
    #4
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jkflens
    Replies:
    2
    Views:
    1,793
    jkflens
    May 30, 2006
  2. Replies:
    1
    Views:
    455
    Peter Bradley
    Apr 10, 2007
  3. Erik Wasser
    Replies:
    5
    Views:
    917
    Peter J. Holzer
    Mar 5, 2006
  4. Replies:
    0
    Views:
    234
  5. emulate removechild in IE 4?

    , Dec 31, 2004, in forum: Javascript
    Replies:
    2
    Views:
    259
    Martin Honnen
    Jan 1, 2005
  6. Replies:
    1
    Views:
    252
  7. Enzo

    RemoveChild

    Enzo, Jun 30, 2005, in forum: Javascript
    Replies:
    7
    Views:
    243
    Michael Winter
    Jul 1, 2005
  8. mikez302
    Replies:
    6
    Views:
    325
    mikez302
    Dec 20, 2007
Loading...