简体   繁体   English

外部 xml dtd 中的实体

[英]entity in external xml dtd

I am trying to put ENTITY in externaL DTD file but its not showing values of ENTITY in XML when it is parsed.我试图将ENTITY放在外部DTD文件中,但在解析时它没有在XML 中显示ENTITY 的值。

But its working when I combine the XML and DTD in one file below is my code for XML and DTD但是当我将XMLDTD 组合在一个文件中时它的工作是我的XMLDTD代码

info.xml信息文件

<!DOCTYPE info SYSTEM "./Note.dtd">  <info>   
<info>
<company>&company_info;</company>   
<privacy_policy>&privacy_policy;</privacy_policy>  </info>
</info>

Note.dtd注意.dtd

<!ENTITY company_info "<name>Test Company</name><location>Berlin</location><phone>1800-000-000</phone>">
<!ENTITY privacy_policy "Lorem ipsum dolor sit amet, consectetur adipisicing elit, .">

info.xml and Note.dtd is in same folder info.xmlNote.dtd是在同一个文件夹

I'm not sure what you're using to parse the XML, but I know Xerces will throw errors about <info> not being declared if you use the file extension ".dtd".我不确定你用什么来解析 XML,但我知道如果你使用文件扩展名“.dtd”,Xerces 会抛出关于<info>未声明的错误。

Try changing "Note.dtd" to "Note.ent".尝试将“Note.dtd”更改为“Note.ent”。

I did this with your sample files and the errors went away.我用你的示例文件做了这个,错误消失了。 Also, I was able to do an identity transform using Saxon on your original info.xml and the entity references were resolved without error.此外,我能够在原始 info.xml 上使用 Saxon 进行身份转换,并且实体引用已正确解析。

 <p> i had the same problem..just use php instead <?php libxml_disable_entity_loader(false); // code injection from the client side $file='<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE login SYSTEM "http://localhost/e.ent"> <login><user>&name;</user><pass>password</pass></login>'; // $dom=new DOMDocument(); $dom->loadXML($file,LIBXML_NOENT | LIBXML_DTDLOAD); $element=$dom->getElementsByTagName('user')[0]; echo $element->nodeValue; ?></p>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM