[erlang-questions] xmerl parsing of DTD

Haobo Yu <>
Thu Jul 19 23:10:52 CEST 2007


I ran into a problem of parsing XML files with an external DTD.  For  
example, the following XML file:

<?xml version="1.0"?>
<!DOCTYPE note SYSTEM "t2.dtd">
<body>Don't forget me this weekend!</body>

When parsed by xmerl 1.1.4, gives an error (I have t2.dtd in the same  

** exited: {{case_clause,{error,enoent}},
              {shell,eval_loop,3}]} **

The test code is here:

test_check_dtd() ->
     Xml = "<?xml version=\"1.0\"?>\n<!DOCTYPE note SYSTEM \"t2.dtd\"> 
heading>\n<body>Don't forget me this weekend!</body>\n</note>\n",
     xmerl_scan:string(Xml, [{validation, off}]).

I found that if I apply the attached patch to xmerl_scan.erl, which  
uncomments two lines that appear to prevent DTD loading if validation  
is off, it works fine.  However, I don't know enough to tell what is  
the right patch.  Would appreciate suggestions.


- Haobo

--- /opt/local/lib/erlang/lib/xmerl-1.1.4/src/xmerl_scan.erl     
2007-04-12 07:28:36.000000000 -0700
+++ xmerl_scan.erl      2007-07-19 11:21:11.000000000 -0700
@@ -715,6 +715,7 @@
      ?dbg("prolog(\"<\")~n", []),

      %% Here we consider the DTD provided by doctype_DTD option,
+    io:format("~p~n", [S0]),
      S1 =
         case S0 of
             #xmerl_scanner{validation=dtd,doctype_DTD=DTD} when list 
(DTD) ->
@@ -1202,8 +1203,8 @@
fetch_DTD(undefined, S) ->
-% fetch_DTD(_,S=#xmerl_scanner{validation=false}) ->
-%     S;
+fetch_DTD(_,S=#xmerl_scanner{validation=off}) ->
+    S;
fetch_DTD(DTDSpec, S)->
      case fetch_and_parse(DTDSpec,S,[{text_decl,true},
{external,subset}}]) of

More information about the erlang-questions mailing list