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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.