1

你能帮我提取xml标签之间的字符串吗?xml输入:

    <Name ns1:translate="yes">Overview</Name>
    <Title ns1:translate="yes">This is a book</Title>
    <Description ns1:translate="yes"/>
    <TextValue ns1:translate="yes">End</TextValue>

预期输出:

    Overview = Overview
    This is a book = This is a book
       =
    End = End
4

2 回答 2

2

If you want just remove tags, you can do it this way:

$ sed 's/<[^>]*>//g'

If you want to repeat the text in tags, you need something like:

$ sed 's/.*>\([^<]*\)<.*/\1 = \1/g'
于 2012-08-07T09:34:38.453 回答
2

一个建议:请使用 PERL 进行 XML 读取/提取。PERL 有许多模块 XML 解析模块 [包括 SAX/DOM]。

甚至 Python 也是 XML 解析的完美选择。

于 2012-08-08T07:29:38.747 回答