XMLStarles removes closing tag

天涯浪子 提交于 2019-12-11 11:38:17

问题


Having trouble with xmlstar. It's removes empty tags, how to disable this?

input:

<tag1>test1</tag1>
<tag3></tag3>
<tag4>test3</tag4>

output:

<tag1>test1</tag1>
<tag3/>
<tag4>test3</tag4>

And i want the same output so is's not removes the closing quote.

Hope someone has a quick answer.


回答1:


In XML, <a></a> and <a/> (note the /) are semantically identical. Whatever application is consuming the document should not care about this change.

I don't know anything about xmlstarlet in particular, but if its serializer doesn't have an option to produce the more verbose form you may need to postprocess the document.

If you absolutely need to former version, you have four choices: Find an XML serializer which will write out empty elements in that form (there may or may not be an option on the one you're using), modify an XML serializer to write out empty elements in that form, write your own XML serializer (not recommended; it's not very difficult but if you're asking this question there are details which will give you trouble), or postprocess the text after writing it out to change all instances of <a></a> to <a/>.

Actually, there's another possibility. If the reason your other program needs the long form is because it expects HTML, you should be using an HTML serializer rather than an XML serializer.




回答2:


I know it's the same. But the reason why i need is the tool there should reed this has not support for this format of xml. It needs the closing tag.

So I will be interested to here from anyone there have an idea.

The header off the file is. So its defiantly the tool reading the file.

<?xml version="1.0" encoding="iso-8859-1"?>

<project>
  <fileVersion>2</fileVersion>
  <configuration>
    <name>Debug</name>
    <toolchain>
      <name>ARM</name>
    </toolchain>


来源:https://stackoverflow.com/questions/21022367/xmlstarles-removes-closing-tag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!