选择xml原始文本 [英] Selecting xml raw text
本文介绍了选择xml原始文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出这样的xml:
<container>
<item>
<xmlText>
<someTag>
<otherTag>
Text
</otherTag>
</someTag>
</xmlText>
</item>
<container>
我想选择item / xmlText下的所有文本。我想打印此节点的所有内容带标签(someTag,otherTag)。
I would like to select all text that is under item/xmlText. I would like to print all the content of this node with tags (someTag, otherTag).
我更愿意用XPath处理这个问题,但这是Java程序的一部分,所以如果有这样的机制我也可以接受它。
I would prefer to handle with this with XPath, but this is part of Java program, so if there is such mechanism I could take it as well.
推荐答案
使用XSLT :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:copy-of select="/container/item/xmlText/node()"/>
</xsl:template>
</xsl:stylesheet>
当在提供的XML文档上应用时(已更正为正确) -formed !!!):
When this is applied on the provided XML document (corrected to be well-formed !!!):
<container>
<item>
<xmlText>
<someTag>
<otherTag>
Text
</otherTag>
</someTag>
</xmlText>
</item>
</container>
生成所需的正确结果:
<someTag>
<otherTag>
Text
</otherTag>
</someTag>
这篇关于选择xml原始文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文