[xml] Bug or expected behaviour with xmlNewChild



This one is really confusing me... I'm the first to admit I'm not at all sure what I'm doing, but:

I'm trying to create an xhtml file as part of an epub. (I've already successfully exported an html and imported an xml file into the program, and I'm getting no error messages.)

My google-fu is weak on this one; I can find nothing relevant in either the archive or generally on the net.

What I want:

<head>

<title>Unknown</title>

<link href="" rel="stylesheet" type="text/css" />

<link href="" rel="stylesheet" type="text/css" />

</head>


and I cannot find a way to make the link elements terminate.


Code:
doc = htmlNewDoc (NULL, NULL);
root_node = xmlNewNode (NULL, BAD_CAST "html");
xmlNewProp (root_node, BAD_CAST "xmlns", BAD_CAST "http://www.w3.org/1999/xhtml");
xmlDocSetRootElement (doc, root_node);
node = xmlNewChild (root_node, NULL, BAD_CAST "head", NULL);

node1 = xmlNewChild (node, NULL, BAD_CAST "title", NULL);
xmlNodeAddContent (node1, BAD_CAST "Title");

node1 = xmlNewChild (node, NULL, BAD_CAST "plink", NULL);
xmlNewProp (node1, BAD_CAST "href", BAD_CAST "../Styles/stylesheet.css");
xmlNewProp (node1, BAD_CAST "rel", BAD_CAST "stylesheet");
xmlNewProp (node1, BAD_CAST "type", BAD_CAST "text/.css");

node1 = xmlNewChild (root_node, NULL, BAD_CAST "body", NULL);
// and so on...


This produces:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title</title>
<plink href="" rel="stylesheet" type="text/.css"></plink>
</head>
<body></body>
</html>

(tabs added for clarity)


but when I replace 'plink' with the desired 'link' I get this:


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Title</title>
<link href="" rel="stylesheet" type="text/.css">
</head>
<body></body>
</html>


in which there is no termination for the link element. It seems to work with anything *except* 'link' as the element name.


Am I doing something really stupid here?


Regards,


Neil




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