我有一個我的java字符串一個XML字符串如下對象:得到一個字符串的元素,它看起來像XML和操縱它在Java
<Record><op>Add</op><sensdata>400188711111</sensdata><id>4</id><a1>1111201090467034</a1></Record>
我需要得到sensdata標籤之間的數據掩蓋它像4001887XXXXX,並準備下面的XML字符串並記錄下來。
<Record><op>Add</op><sensdata>4001887XXXXX</sensdata><id>4</id><a1>1111201090467034</a1></Record>
sensdata標記可以位於較低或較高位置。
有什麼更好的方法來做到這一點?我是否必須使用一些字符串操作或正則表達式或XML解析器來執行此操作?
我有一個附加到這個問題的小查詢。如果我需要
之間
<Record> </Record>
即
<op>Add</op><sensdata>4001887XXXXX</sensdata><id>4</id><a1>1111201090467034</a1>
數據我可以得到使用XML解析器。我能夠得到像Add4001887XXXXX41111201090467034這樣的值。但沒有標籤。
它的XML - 所以使用XML解析器。 – 2014-09-12 13:33:37
使用Xpath表達式來獲取值,然後使用DOM庫來附加到XML。 – Sid 2014-09-12 13:35:12
只是請[不要使用正則表達式。](http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags) – 2014-09-12 13:35:36