复制 XML 的某些部分而不重写它们 [英] Duplicate some parts of XML without rewriting them
本文介绍了复制 XML 的某些部分而不重写它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含重复部分的 XML 文件,例如:
I have an XML file with duplicate parts such as:
<argument name="create">
<argument name="user" type="text"></argument>
<argument name="password" type="password"></argument>
(and so on)
</argument>
<argument name="update">
<argument name="user" type="text"></argument>
<argument name="password" type="password"></argument>
(and so on)
</argument>
我希望将 create 和 update 之间的部分声明一次,然后在 create 和 update 之间使用单行附加它.这将为我节省很多行.
I would like to have the part between create and update declared once then append it between create and update with a one-liner. This would save me a lot of lines.
有没有办法在 XML 中做到这一点?
Any way to do that in XML?
推荐答案
您可以为此使用 SGML/XML实体",它可以包含替换文本或标记以便在多个地方重复使用:
You can use SGML/XML"entities" for that, which can contain replacement text or markup for reuse at multiple places:
<!DOCTYPE arguments [
<!ENTITY user-and-password
'<argument name="user" type="text"/>
<argument name="password" type="password"/>'>
]>
<arguments>
<argument name="create">
&user-and-password;
</argument>
<argument name="update">
&user-and-password;
</argument>
</arguments>
请注意,您必须调整 DOCTYPE:它必须与您的 XML 的文档元素匹配.
Note that you have to adapt the DOCTYPE: it must match the document element of your XML.
这篇关于复制 XML 的某些部分而不重写它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文