Reputation: 1573
I am trying to put ENTITY in externaL DTD file but its not showing values of ENTITY in XML when it is parsed.
But its working when I combine the XML and DTD in one file below is my code for XML and DTD
info.xml
<!DOCTYPE info SYSTEM "./Note.dtd"> <info>
<info>
<company>&company_info;</company>
<privacy_policy>&privacy_policy;</privacy_policy> </info>
</info>
Note.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
Upvotes: 0
Views: 1457
Reputation: 1
<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>
Upvotes: 0
Reputation: 52888
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".
Try changing "Note.dtd" to "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.
Upvotes: 1