Include external XML ENTITIES using SYSTEM while resolving path with $ENV variable

断了今生、忘了曾经 提交于 2019-12-24 11:54:12

问题


Looking at some posts and others, I'm close to what I'm looking for, but not there yet.

Overall goal

To have XML ENTITY files included within other XML files, with the URI to SYSTEM taken from the an environment variable!

Sample XML ENTITY files (not sure if xml declaration needed)

$XML_PATH_SET_PER_ENV/entites/$CLIENT/entities.ent

<!ENTITY COMPANY_ID "9800">
<!ENTITY PARENT_ID "98100">
<!ENTITY ACCOUNT_NAME "THE SUN PEOPLE">
<!ENTITY ACCOUNT_AB "TSP">

or $XML_PATH_SET_PER_ENV/entites/$CLIENT/entities.ent

<!ENTITY COMPANY_ID "7900">
<!ENTITY PARENT_ID "98500">
<!ENTITY ACCOUNT_NAME "FRUITS VEGGIES N MORE">
<!ENTITY ACCOUNT_AB "FVNM">

or $XML_PATH_SET_PER_ENV/entites/$CLIENT/entities.ent

<!ENTITY COMPANY_ID "84500">
<!ENTITY PARENT_ID "861675">
<!ENTITY ACCOUNT_NAME "THE SUN PEOPLE">
<!ENTITY ACCOUNT_AB "TSP">

Then within any XML file, I wish to pull in a specific entities.ent as needed:

doc.xml

<?xml version="1.0" standalone="no" ?>
<!DOCTYPE TEST [

    <!ENTITY % get_em SYSTEM "entities.ent" >
    %get_em;

]>

<TEST>
        <COMPANY_ID>&COMPANY_ID;</COMPANY_ID>
</TEST>

However, before getting to my stated goal, I struggling first to get this simple doc.xml to work:

$ ls -lrt doc.xml entities.ent
-rw-r--r--. 1 user other 186 Dec 28 14:33 entities.ent
-rw-r--r--. 1 user other 182 Dec 28 14:34 doc.xml

And xmllint is not happy :(

$ xmllint --noout doc.xml
doc.xml:10: parser error : Entity 'COMPANY_ID' not defined
        <COMPANY_ID>&COMPANY_ID;</COMPANY_ID>
                                        ^

回答1:


To get the simple test to work, just need extra options to xmllint!

$ xmllint --loaddtd --noent --dropdtd doc.xml
<?xml version="1.0" standalone="no"?>
<TEST>
        <COMPANY_ID>84500</COMPANY_ID>
</TEST>

No errors!



来源:https://stackoverflow.com/questions/34499647/include-external-xml-entities-using-system-while-resolving-path-with-env-variab

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