Using doctype with XML

I use a separate .dtd file as doctype for my custom XML file:

names.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE name SYSTEM "names.dtd">
<names>
    <name>
        <text>Pep&eacute;</text>
        <creator>&lost;</creator>
        <history>&lost;</history>
    </name>
    <name>
        <text>Charles</text>
        <creator>James</creator>
        <history>&lost;</history>
    </name>
</names>

names.dtd

<!ELEMENT name (text, creator+, history)>
<!ELEMENT text (#PCDATA)>
<!ELEMENT creator (#PCDATA)>
<!ELEMENT history (#PCDATA)>

<!-- Placeholder/unknown history or creator name -->
<!ENTITY lost "Lost in the depths of time.">
<!ENTITY eacute "ÃĐ">

However, when trying to access names.xml, the following error occurs:

XML parsing error: undefined object Location: http: //localhost/.../names.xml Line Number 5, column 18:

<text>Pep&eacute;</text>
---------^

Just for clarification, names.xml and names.dtd are in the same directory and using http: //localhost/.../names.dtd does not work either.

This seems to work when placed <!ENTITYinside <!DOCTYPEat names.xml. Can anyone advise this?

+3
source share
2 answers

Firefox, , dtd, . Firefox xml dtd XML-. XML- IE, MSXML.

XML- IE DTD . eacute, . , , ...

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE NAME SYSTEM "names.dtd">
<names>
    <name>
        <text>Pep&eacute;</text>
        <creator>&lost;</creator>
        <history>&lost;</history>
    </name>
    <name>
        <text>Charles</text>
        <creator>James</creator>
        <history>&lost;</history>
   </name>
</names>

<!ELEMENT name (text, creator+, history)>
<!ELEMENT text (#PCDATA)>
<!ELEMENT creator (#PCDATA)>
<!ELEMENT history (#PCDATA)>

<!ENTITY lost "Lost in the depths of time.">
<!ENTITY eacute "&#233;">
+2

Firefox DTD ( Safari; , ). DTD XML xmllint, , DTD:

$ xmllint --loaddtd names.xml 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE names SYSTEM "names.dtd">
<names>
    <name>
        <text>Pep&eacute;</text>
        <creator>&lost;</creator>
        <history>&lost;</history>
    </name>
    <name>
        <text>Charles</text>
        <creator>James</creator>
        <history>&lost;</history>
    </name>
</names>

edit. hsivonen , DTD - , DOCTYPE DTD . , (RELAX NG ), DTD, .

+2

Source: https://habr.com/ru/post/1705977/


All Articles