Re: [xml] Problem Creating DTD for programatically generated document



I have however been able to get a normal HTML5 doctype declatation (e.g. <!DOCTYPE HTML> to render correctly using:xmlNewDtd($1,(const xmlChar *)"HTML",NULL,NULL) .


>I'm not sure what you mean by "xmlNewDtd fails." I tried with the order
>reversed and there was no 'failure' (other than what I've always
>experienced - no DOCTYPE declaration - which might be an error on my part).

Precisely that, no DOCTYPE declaration.

>It is my understanding that the two are in the correct order. ExternalID
>refers to the Formal Public Identifier and SystemID refers to the actual
>URI of the DTD [1].
>
>In your case:
  >- ExternalID: "-//W3C//DTD XHTML 1.0 Strict//EN"
  >- SystemID: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
Well field name in API call may be correct given your definition, but as soo an you put anything starting with http in the system ID argument you will fail to get a DOCTYPE. What I think is happening is the library is applying the wrong formatting validation to the wrong fields (e.g. validating system ID reqirements against the extarnal arg, and validating external ID requirement against the system arg)

>I don't know if this is a bug, but you could get the desired behavior
>using xmlCreateIntSubset, instead.
I'll have to look at xmlCreateIntSubset, thanks for the tip. Though I think I will pull the libxml2 source and have a look at xmlNewDtd I am rather curious if this is a bug.

>I'd appreciate it if you could share the way in which you force the
>newly created dtd (dtd2) to be output with the doc
Well this isn't C but I think you should be able to translate easily enough

println("----------Test programatic w/DTD document constructionl-----------");
ar xml_doc4 = xml_new_doc("1.0");
var dtd2 = xml_new_html_dtd(xml_doc3); // Works !DOCTYPE HTML , uses xmlNewDtd($1,(const xmlChar *)"HTML",NULL,NULL)
/* Displays DOCTYPE in revers order but at leasts renders DOCTYPE
var dtd2 = xml_new_dtd(xml_doc3,"HTML","http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd","-//W3C//DTD XHTML 1.0 Strict//EN");
*/
var dtd_node:xml_node_ptr;
var r41 = xml_doc_set_root_element(xml_doc4, xml_node_ptr_of_xml_dtd_ptr(dtd2));
if isNull[xml_node_ptr](r41) do
  println("DTD not set");
done
var root_node4 = xml_new_node( "html");
var r42 = xml_add_child(xml_node_ptr_of_xml_doc_ptr(xml_doc4),root_node4);
if isNull[xml_node_ptr](r42) do
  println("Node r42 not set");
done
val e41 = xml_new_child(root_node4, Null[xml_ns_ptr],  "body","");
if isNull[xml_node_ptr](e41) do
  println("Node e42 not set");
done
val e42 = xml_new_text_child(e41, Null[xml_ns_ptr],  "div","Hello World");
if isNull[xml_node_ptr](e42) do
  println("Node e42 not set");
done
println("----------------------------------------");
print(xml_doc_dump(xml_doc4));
println("----------------------------------------");



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]