Can ENTITY declarations be nested in referenced XML files?

前端 未结 1 1994
一生所求
一生所求 2021-01-21 03:24

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:

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-21 03:42

    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

    
    
        
        
    ]>
    
    
        
            Chapter 1
            §ion1;
            §ion2;
            §ion3;
        
    
    

    And the other document file:

    
    
        
        
    ]>
    
    Section 3 §ion3_a; §ion3_b; §ion3_c;

    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.

    
    
    
        
    
        %entities;
    
    ]>
    
    
        &product.name;
        Release Notes
        
            &product.release.date;
            
        
    
        
        
        
    
    

    A chapter file (put in the directory changes), as which is included by the previous document. If xi:include is used as above, it will stop rendering, if the href attribute can not be solved.

    
    
    
        
    
        %entities;
    
    ]>
    
    
        Release 2.0
        
            Information given in this chapter applies for &product.name; v2.0.
        
    
        
            FIXME File not found: "§ion-changes;"
        
    
    
    

    Here the xi:include is used with a fallback, so if the href attribute of the xi: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 the href 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.

    0 讨论(0)
提交回复
热议问题