ENTITY 声明可以嵌套在引用的 XML 文件中吗?
我正在处理一个相当大的 DocBook XML 文档。主书有章节,但通过使用实体引用包括所有小节。像这样的东西:
main.book.xml
:
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
[
<!ENTITY section1 SYSTEM "../fragments/section1.xml">
<!ENTITY section2 SYSTEM "../fragments/section2.xml">
<!ENTITY section3 SYSTEM "../fragments/section3.xml">
<!ENTITY section3_a SYSTEM "../fragments/section3_a.xml">
<!ENTITY section3_b SYSTEM "../fragments/section3_b.xml">
<!ENTITY section3_c SYSTEM "../fragments/section3_c.xml">
]>
<book>
<chapter>
<title>Chapter 1</title>
§ion1;
§ion2;
§ion3;
</chapter>
</book>
第 3 部分又分为三个 xml 文件,其内容通过引用包含在内,如下所示:
section3.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<section id="Section3">
<title>Section 3</title>
§ion3_a;
§ion3_b;
§ion3_c;
</section>
问题:有没有办法将仅第 3 节使用的 ENTITY 声明(即section3_a、section3_b 等)移动到 section3.xml
,而不是在 main.book.xml
中声明它们?
I'm working on a rather large DocBook XML document. The main book has the chapters but includes all the subsections by reference using entities. Something like this:
main.book.xml
:
<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
[
<!ENTITY section1 SYSTEM "../fragments/section1.xml">
<!ENTITY section2 SYSTEM "../fragments/section2.xml">
<!ENTITY section3 SYSTEM "../fragments/section3.xml">
<!ENTITY section3_a SYSTEM "../fragments/section3_a.xml">
<!ENTITY section3_b SYSTEM "../fragments/section3_b.xml">
<!ENTITY section3_c SYSTEM "../fragments/section3_c.xml">
]>
<book>
<chapter>
<title>Chapter 1</title>
§ion1;
§ion2;
§ion3;
</chapter>
</book>
Section 3 is in turn divided into three more xml files whose content is included by reference like so:
section3.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<section id="Section3">
<title>Section 3</title>
§ion3_a;
§ion3_b;
§ion3_c;
</section>
QUESTION: Is there a way to move the ENTITY declarations used only by Section 3 (i.e. section3_a, section3_b, etc) to section3.xml
instead of declaring them in main.book.xml
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这是可能的,只需将它们添加到文档中,您就可以使用它们。
但我强烈反对使用实体,因为包括其他文档(部分)!您迟早会遇到一个(或多个)文档(部分)不可用的困难。您的文档将不会呈现,并且搜索导致它的问题相当令人讨厌。更好的解决方案是使用 XInclude 来包含文档。
包含实体条目的解决方案
以及其他文档文件:
提示:您甚至可以将所有实体一起移出文档,请参阅我就此问题写的答案DocBook 宏?
使用 XInclude 的解决方案
下面是如何使用 XInclude 设置文档的示例。实体条目用于小字符串。并使用 XInclude 来包含文件。
章节文件(放在
changes
目录中),如上一个文档中所包含的那样。如果像上面那样使用xi:include
,如果href
属性无法解析,它将停止渲染。这里 xi:include 与后备一起使用,因此如果无法解决 xi:include 的
href
属性,则后备为渲染到文档中(这将显示一个带有 FIXME 的段落。这里实际上使用一个实体,用于引用文档(位置)。这很棒,因为该引用可以在href
中使用,并且FIXME 部分!在引用实体文件
../entities.ent
时要小心,当无法解析时,这可能会产生严重的错误。Yes, this is possible, just add them to the document, you are using them.
But I strongly discourage the use of entities, for including other document (parts)! As soon or later you will run in the difficulty, that one (or more) of the document (parts) are not available. Your document will not render and searching for the issue causing it is rather nasty. A far better solution is to use XInclude, for inclusion of documents.
Solution with ENTITY entries
And the other document file:
TIP: You can even move the entities all together out of your documents, see the answer I wrote on this question DocBook macros?
Solution with XInclude
Here then an example of how to set up documents with XInclude. Entity entries are used for small strings. And using XInclude, for file inclusion.
A chapter file (put in the directory
changes
), as which is included by the previous document. Ifxi:include
is used as above, it will stop rendering, if thehref
attribute can not be solved.Here the
xi:include
is used with a fallback, so if thehref
attribute of thexi:include
could not be solved, the fallback is rendered into the document (This will show a paragraph with FIXME in it. Here using actually an entity, for referencing the document (location). This is great as that reference can then be used in thehref
and FIXME section!Be careful with referencing back to the entities file
../entities.ent
This again can give nasty errors when it can not be resolved.