473,395 Members | 1,975 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Unexpected behavior when creating xhtml documents

Hey everybody,

The following has been posted before (2 years ago) but no response was
added. Therefor again, the following code for creating xhtml file:

<?php

error_reporting(6143);

$xmlns = "http://www.w3.org/1999/xhtml";
$lang = "en";

$xhtml_1_strict = new DomImplementation();

$dtd_xhtml_1_strict = $xhtml_1_strict->createDocumentType("html", "-//
W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/
xhtml1-strict.dtd");

$xhtml_1_strict_document = $xhtml_1_strict->createDocument("", "",
$dtd_xhtml_1_strict);
$xhtml_1_strict_document->encoding = "UTF-8";
$xhtml_1_strict_document->standalone = "no";

$html = $xhtml_1_strict_document->createElementNS($xmlns, "html");
$html->setAttribute("xml:lang", $lang);

$head = $xhtml_1_strict_document->createElement("head");
$html->appendChild($head);

$title = $xhtml_1_strict_document->createElement("title", "Testing the
DOM in PHP5");
$head->appendChild($title);

$base = $xhtml_1_strict_document->createElement("base");
$base->setAttribute("href", "http://test.beatter.com");
$head->appendChild($base);

$meta = $xhtml_1_strict_document->createElement("meta");
$meta->setAttribute("http-equiv", "Content-Type");
$meta->setAttribute("content", "application/xhtml+xml;UTF-8");
$head->appendChild($meta);

$body = $xhtml_1_strict_document->createElement("body");
$html->appendChild($body);

$xhtml_1_strict_document->appendChild($html);

header("Content-type: application/xhtml+xml;UTF-8");
echo($xhtml_1_strict_document->saveXML());

?>

the expected output would be:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Testing the DOM in PHP5</title><base href="http://
test.beatter.com" />
<meta http-equiv="Content-Type" content="application/xhtml
+xml;UTF-8" />
</head>
<body>
</body>
</html>

but the output is:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />
<title>Testing the DOM in PHP5</title><base href="http://
test.beatter.com" />
</head>
<body>
</body>
</html>

Why does php add this node by itself? Why can't I override that
behavior? Why does php change the order of outputing the elements (I'm
appending, not pre-pending to the head element)?

Thanks,

Marijn

Jun 6 '07 #1
4 1725
On Jun 6, 7:23 pm, Marijn <marijn.huizendv...@gmail.comwrote:
Hey everybody,

The following has been posted before (2 years ago) but no response was
added. Therefor again, the following code for creating xhtml file:

<?php

error_reporting(6143);

$xmlns = "http://www.w3.org/1999/xhtml";
$lang = "en";

$xhtml_1_strict = new DomImplementation();

$dtd_xhtml_1_strict = $xhtml_1_strict->createDocumentType("html", "-//
W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/
xhtml1-strict.dtd");

$xhtml_1_strict_document = $xhtml_1_strict->createDocument("", "",
$dtd_xhtml_1_strict);
$xhtml_1_strict_document->encoding = "UTF-8";
$xhtml_1_strict_document->standalone = "no";

$html = $xhtml_1_strict_document->createElementNS($xmlns, "html");
$html->setAttribute("xml:lang", $lang);

$head = $xhtml_1_strict_document->createElement("head");
$html->appendChild($head);

$title = $xhtml_1_strict_document->createElement("title", "Testing the
DOM in PHP5");
$head->appendChild($title);

$base = $xhtml_1_strict_document->createElement("base");
$base->setAttribute("href", "http://test.beatter.com");
$head->appendChild($base);

$meta = $xhtml_1_strict_document->createElement("meta");
$meta->setAttribute("http-equiv", "Content-Type");
$meta->setAttribute("content", "application/xhtml+xml;UTF-8");
$head->appendChild($meta);

$body = $xhtml_1_strict_document->createElement("body");
$html->appendChild($body);

$xhtml_1_strict_document->appendChild($html);

header("Content-type: application/xhtml+xml;UTF-8");
echo($xhtml_1_strict_document->saveXML());

?>

the expected output would be:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Testing the DOM in PHP5</title><base href="http://
test.beatter.com" />
<meta http-equiv="Content-Type" content="application/xhtml
+xml;UTF-8" />
</head>
<body>
</body>
</html>

but the output is:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />
<title>Testing the DOM in PHP5</title><base href="http://
test.beatter.com" />
</head>
<body>
</body>
</html>

Why does php add this node by itself? Why can't I override that
behavior? Why does php change the order of outputing the elements (I'm
appending, not pre-pending to the head element)?

Thanks,

Marijn
I've run into this problem, too. Unfortunately I've been unable to
find /any/ documentation on how/where/why this happens. It also seems
to depend on which version of the underlying XML libraries PHP is
using. I, too, would love to hear from anyone that has some insight
into this "feature."

Jun 7 '07 #2
On Jun 7, 3:27 pm, ZeldorBlat <zeldorb...@gmail.comwrote:
On Jun 6, 7:23 pm, Marijn <marijn.huizendv...@gmail.comwrote:
Hey everybody,
The following has been posted before (2 years ago) but no response was
added. Therefor again, the following code for creating xhtml file:
<?php
error_reporting(6143);
$xmlns = "http://www.w3.org/1999/xhtml";
$lang = "en";
$xhtml_1_strict = new DomImplementation();
$dtd_xhtml_1_strict = $xhtml_1_strict->createDocumentType("html", "-//
W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/
xhtml1-strict.dtd");
$xhtml_1_strict_document = $xhtml_1_strict->createDocument("", "",
$dtd_xhtml_1_strict);
$xhtml_1_strict_document->encoding = "UTF-8";
$xhtml_1_strict_document->standalone = "no";
$html = $xhtml_1_strict_document->createElementNS($xmlns, "html");
$html->setAttribute("xml:lang", $lang);
$head = $xhtml_1_strict_document->createElement("head");
$html->appendChild($head);
$title = $xhtml_1_strict_document->createElement("title", "Testing the
DOM in PHP5");
$head->appendChild($title);
$base = $xhtml_1_strict_document->createElement("base");
$base->setAttribute("href", "http://test.beatter.com");
$head->appendChild($base);
$meta = $xhtml_1_strict_document->createElement("meta");
$meta->setAttribute("http-equiv", "Content-Type");
$meta->setAttribute("content", "application/xhtml+xml;UTF-8");
$head->appendChild($meta);
$body = $xhtml_1_strict_document->createElement("body");
$html->appendChild($body);
$xhtml_1_strict_document->appendChild($html);
header("Content-type: application/xhtml+xml;UTF-8");
echo($xhtml_1_strict_document->saveXML());
?>
the expected output would be:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Testing the DOM in PHP5</title><base href="http://
test.beatter.com" />
<meta http-equiv="Content-Type" content="application/xhtml
+xml;UTF-8" />
</head>
<body>
</body>
</html>
but the output is:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8" />
<title>Testing the DOM in PHP5</title><base href="http://
test.beatter.com" />
</head>
<body>
</body>
</html>
Why does php add this node by itself? Why can't I override that
behavior? Why does php change the order of outputing the elements (I'm
appending, not pre-pending to the head element)?
Thanks,
Marijn

I've run into this problem, too. Unfortunately I've been unable to
find /any/ documentation on how/where/why this happens. It also seems
to depend on which version of the underlying XML libraries PHP is
using. I, too, would love to hear from anyone that has some insight
into this "feature."
unfortunately DOM/XML documentation is very poor by itself. Especially
concerning this topic. Is the problem solvable by installing another
DOM/XML Library?

Jun 8 '07 #3
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Marijn wrote:
unfortunately DOM/XML documentation is very poor by itself. Especially
concerning this topic. Is the problem solvable by installing another
DOM/XML Library?
Hi, you are welcome to submit specific concerns and clarifications to
the PHP documentation team at news://news.php.net/php.doc

The DOM extension is built off of libxml, so quirks like these are
likely bugs in libxml and not DOM. Running your snippet on PHP 5.0.3,
with libxml 2.6.11, I get (slightly formatted for readability):

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//
W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/
xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<title>Testing the DOM in PHP5</title>
<base href="http://test.beatter.com"/>
<meta http-equiv="Content-Type" content="application/xhtml+xml;UTF-8"/>
</head>
<body/>
</html>

Which is the expected behavior. As you may already know, 5.2.3 and
2.6.28 are the latest versions for PHP and libxml respectively, so you
may be running on an ancient version of libxml. If this is the case,
please upgrade or recompile the extension with a newer version of libxml.

- --
Edward Z. Yang GnuPG: 0x869C48DA
HTML Purifier <htmlpurifier.org Anti-XSS HTML Filter
[[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGaK6XqTO+fYacSNoRAj8nAJ94DFXP2vL53rYKZE8oZp qr8JlpbACfWQgX
5kpzr7VMP7744olgYN8T9/M=
=ESgZ
-----END PGP SIGNATURE-----
Jun 8 '07 #4
Hi, you are welcome to submit specific concerns and clarifications to
the PHP documentation team at news://news.php.net/php.doc
Might just do that. Will need to gain a little bit more self
confidence about my code thouht ;)
Which is the expected behavior. As you may already know, 5.2.3 and
2.6.28 are the latest versions for PHP and libxml respectively, so you
may be running on an ancient version of libxml. If this is the case,
please upgrade or recompile the extension with a newer version of libxml.
Looks like it is time I talked to my hosting provider <http://
mediatemple.net>. Seem to be running 2.6.16 for libxml and php 5.2.2

Thanks in advance

Jun 8 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

23
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to...
16
by: Mcginkel | last post by:
I am trying to find a way to load XHTML content in an Iframe. I use to do this in html by using the following code : var iframeObject = document.createElement("iframe");...
11
by: Simon Shutter | last post by:
Forgive me if I am posting to wrong newsgroup and for a couple of loaded questions. First, from what I understand, one of the advantages of XHTML/CSS is the ability of screen readers/braille...
6
by: Samuel M. Smith | last post by:
I have been playing around with a subclass of dict wrt a recipe for setting dict items using attribute syntax. The dict class has some read only attributes that generate an exception if I try to...
17
by: Christoph Schneegans | last post by:
Hi! I would like to announce XHTML Proxy, a service that allows more accurate testing of XHTML documents. <http://hixie.ch/advocacy/xhtml> states that "Sending XHTML as text/html Considered...
11
by: Kidogg | last post by:
Hi all, I'm attempting to write a validator for some email template files we use as part of our e-commerce application (incidentally in C#) and I've run into a problem as I'm not a huge user of...
14
by: Stanimir Stamenkov | last post by:
I've found some contradiction I want to resolve. <http://www.w3.org/MarkUp/2004/xhtml-faq#mime11states: I've noted "_disallowed_ text/html" and "_must_ be sent with an XML-related media...
13
by: =?Utf-8?B?Qi4gQ2hlcm5pY2s=?= | last post by:
I am not accustomed to creating xml files programmatically. The big picture is this: This will be in VB/VS 2005/ winforms. I have a DTD, a sample XML, and an outside data source I will use to...
2
by: SMH | last post by:
I am in the process of converting all HTML documents, including many dynamic/interactive documents, to XHTML documents (because I want to incorporate SVG and MathML, among other things). I am...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.