How to remove the white spaces between tags in XML

后端 未结 7 907
太阳男子
太阳男子 2020-12-06 18:00

I created an XML document using Java in my android application. I have to call a web service in my application and pass this XML as an argument there. But my problem is ther

7条回答
  •  [愿得一人]
    2020-12-06 18:19

    This worked for me, thank you. As a caveat, although this is actually useful for my purpose, I noticed that it can also remove text content if that consists only of whitespace. For example, running the following:

    String xmlIn = "  \t\t \r\n text ";
    String xmlOut = xmlIn.replaceAll("(?:>)(\\s*)<", "><");
    System.out.println(xmlOut);
    

    gives the following:

     text 
    

提交回复
热议问题