xi:include and global entity

T

Thomas Sommer

Hi,

I know doing something like this

<!DOCTYPE section PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"
[<!ENTITY test PUBLIC "BLA" "http://localhost/dummy/test">]>

<section><title/>
<programlisting><xi:include href="&test;" parse="text"
xmlns:xi="http://www.w3.org/2001/XInclude"/></programlisting>
</section>

Will not work but maybe someone knows a workaround.
Basically I want to insert my programlisting from a global entity.
It works if I put the CDATA in front and at the end
in the text file but I don't like that since it alters the file.

Does anyone have a bright idea how to solve this issue?

Thanks Thomas
 
R

Richard Tobin

Basically I want to insert my programlisting from a global entity.

Why do you need to put the contents of the file in an entity? Why
not just do

<xi:include href="http://localhost/dummy/test" parse="text"/>

?

An ugly trick is to do something like this:

<!ENTITY % test PUBLIC "BLA" "http://localhost/dummy/test">
<!-- NB test is a parameter entity! -->
<!ENTITY source "<![CDATA[%test;]]>">

This won't work if your source contains ]]> of course.

-- Richard
 
T

Thomas Sommer

Why do you need to put the contents of the file in an entity? Why
not just do

<xi:include href="http://localhost/dummy/test" parse="text"/>

I know this works and would do the job if the catalog would remap this to
"file:///home/dummy/docbook/some more dirs/test"
I am about to set up my directory structure right now but I don't know if it
might change later on. Using some global entities will save me from editing
every single file (I hope). But maybe there is some better solution or this
is totally unnecessary.
An ugly trick is to do something like this:

<!ENTITY % test PUBLIC "BLA" "http://localhost/dummy/test">
<!-- NB test is a parameter entity! -->
<!ENTITY source "<![CDATA[%test;]]>">
I get:
PEReferences forbidden in internal subset
<!ENTITY source "<![CDATA[%test;]]>">

While in the file I only have:
Some Text
 
T

Thomas Sommer

Yes you have to put it in an external DTD. You can't use parameter entities
like that in the internal subset.

Ok, now the error is gone but I don't get the stuff from the file.
It is loaded though. If I do
<!ENTITY % test PUBLIC "BLA" "http://localhost/dummy/test">
%test;

I get complains about wrong syntax (of course).


Ok I can use the source entity but there will be no text put into
the xml-file even without the CDATA.

Any further ideas

Thanks Thomas
 
R

Richard Tobin

Ok, now the error is gone but I don't get the stuff from the file.

This works for me. It includes the contents of test.c:

foo.xml:

<!DOCTYPE foo SYSTEM "foo.dtd">
<foo>
&source;
</foo>

foo.dtd:

<!ENTITY % test PUBLIC "BLA" "test.c">
<!ENTITY source "<![CDATA[%test;]]>">

But an XInclude solution is better, because ampersands in test.c still
cause problems (I should have realised this before).

-- Richard
 
T

Thomas Sommer

It validates but I still don't get any output. Here the debug info:

xmllint --debugent --valid foo.xml
new input from file: foo.xml
new input from file: foo.dtd
Pushing input 1 :
String decoding PE Reference: %test;]]>
<?xml version="1.0"?>
<!DOCTYPE foo SYSTEM "foo.dtd">
<foo>
&source;
</foo>
DOCUMENT
No entities in internal subset
Entities in external subset
source : INTERNAL GENERAL,
orig "<![CDATA[%test;]]>"
content "<![CDATA[]]>"


As you see the content is empty but maybe I am just too stupid to use
xmllint.

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top