473,804 Members | 2,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 DomImplementati on();

$dtd_xhtml_1_st rict = $xhtml_1_strict->createDocument Type("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_st rict);
$xhtml_1_strict _document->encoding = "UTF-8";
$xhtml_1_strict _document->standalone = "no";

$html = $xhtml_1_strict _document->createElementN S($xmlns, "html");
$html->setAttribute(" xml:lang", $lang);

$head = $xhtml_1_strict _document->createElement( "head");
$html->appendChild($h ead);

$title = $xhtml_1_strict _document->createElement( "title", "Testing the
DOM in PHP5");
$head->appendChild($t itle);

$base = $xhtml_1_strict _document->createElement( "base");
$base->setAttribute(" href", "http://test.beatter.co m");
$head->appendChild($b ase);

$meta = $xhtml_1_strict _document->createElement( "meta");
$meta->setAttribute(" http-equiv", "Content-Type");
$meta->setAttribute(" content", "applicatio n/xhtml+xml;UTF-8");
$head->appendChild($m eta);

$body = $xhtml_1_strict _document->createElement( "body");
$html->appendChild($b ody);

$xhtml_1_strict _document->appendChild($h tml);

header("Content-type: application/xhtml+xml;UTF-8");
echo($xhtml_1_s trict_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>Testin g the DOM in PHP5</title><base href="http://
test.beatter.co m" />
<meta http-equiv="Content-Type" content="applic ation/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>Testin g the DOM in PHP5</title><base href="http://
test.beatter.co m" />
</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 1742
On Jun 6, 7:23 pm, Marijn <marijn.huizend v...@gmail.comw rote:
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 DomImplementati on();

$dtd_xhtml_1_st rict = $xhtml_1_strict->createDocument Type("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_st rict);
$xhtml_1_strict _document->encoding = "UTF-8";
$xhtml_1_strict _document->standalone = "no";

$html = $xhtml_1_strict _document->createElementN S($xmlns, "html");
$html->setAttribute(" xml:lang", $lang);

$head = $xhtml_1_strict _document->createElement( "head");
$html->appendChild($h ead);

$title = $xhtml_1_strict _document->createElement( "title", "Testing the
DOM in PHP5");
$head->appendChild($t itle);

$base = $xhtml_1_strict _document->createElement( "base");
$base->setAttribute(" href", "http://test.beatter.co m");
$head->appendChild($b ase);

$meta = $xhtml_1_strict _document->createElement( "meta");
$meta->setAttribute(" http-equiv", "Content-Type");
$meta->setAttribute(" content", "applicatio n/xhtml+xml;UTF-8");
$head->appendChild($m eta);

$body = $xhtml_1_strict _document->createElement( "body");
$html->appendChild($b ody);

$xhtml_1_strict _document->appendChild($h tml);

header("Content-type: application/xhtml+xml;UTF-8");
echo($xhtml_1_s trict_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>Testin g the DOM in PHP5</title><base href="http://
test.beatter.co m" />
<meta http-equiv="Content-Type" content="applic ation/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>Testin g the DOM in PHP5</title><base href="http://
test.beatter.co m" />
</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...@gma il.comwrote:
On Jun 6, 7:23 pm, Marijn <marijn.huizend v...@gmail.comw rote:
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 DomImplementati on();
$dtd_xhtml_1_st rict = $xhtml_1_strict->createDocument Type("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_st rict);
$xhtml_1_strict _document->encoding = "UTF-8";
$xhtml_1_strict _document->standalone = "no";
$html = $xhtml_1_strict _document->createElementN S($xmlns, "html");
$html->setAttribute(" xml:lang", $lang);
$head = $xhtml_1_strict _document->createElement( "head");
$html->appendChild($h ead);
$title = $xhtml_1_strict _document->createElement( "title", "Testing the
DOM in PHP5");
$head->appendChild($t itle);
$base = $xhtml_1_strict _document->createElement( "base");
$base->setAttribute(" href", "http://test.beatter.co m");
$head->appendChild($b ase);
$meta = $xhtml_1_strict _document->createElement( "meta");
$meta->setAttribute(" http-equiv", "Content-Type");
$meta->setAttribute(" content", "applicatio n/xhtml+xml;UTF-8");
$head->appendChild($m eta);
$body = $xhtml_1_strict _document->createElement( "body");
$html->appendChild($b ody);
$xhtml_1_strict _document->appendChild($h tml);
header("Content-type: application/xhtml+xml;UTF-8");
echo($xhtml_1_s trict_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>Testin g the DOM in PHP5</title><base href="http://
test.beatter.co m" />
<meta http-equiv="Content-Type" content="applic ation/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>Testin g the DOM in PHP5</title><base href="http://
test.beatter.co m" />
</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>Testin g the DOM in PHP5</title>
<base href="http://test.beatter.co m"/>
<meta http-equiv="Content-Type" content="applic ation/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.o rg 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 +fYacSNoRAj8nAJ 94DFXP2vL53rYKZ E8oZpqr8JlpbACf WQgX
5kpzr7VMP7744ol gYN8T9/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
4096
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 <foo/>) From XHTML specification:
16
7121
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"); MyDiv.appendChild(iframeObject); var data = "<html><head><title>testing</title></head><body>data</body></html>" iframeObject.contentDocument.open(); iframeObject.contentDocument.writeln(data);
11
1972
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 agents to provide an improved experience than HTML with table layout. Notwithstanding the leadership of Chevrolet, Amnesty International and others, at what point do you think XHTML/CSS will become the preferred approach? Will it be when the number...
6
6011
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 assign a value to them. I wanted to trap for this exception in a subclass using super but it doesn't happen. I have read Guido's tutorial on new style classes and Shalabh's tuturial on new style attributes and methods, and thought I understood...
17
2005
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 Harmful" since "authors write XHTML that makes assumptions that are only valid for tag soup or HTML4 UAs" and might find that the "site breaks horribly" when they decide to "send the same content as application/xhtml+xml".
11
2207
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 XML. Essentially an email template can contain any valid XHTML, but also has tags such as <membershipcardheaderand <membershipcardfooterthat can appear anywhere in the body of the HTML. I've managed to download the XSD for XHTML transitional...
14
1870
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 type" here as strong requirement. On the other hand the current XHTML 1.1 draft <http://www.w3.org/TR/2007/WD-xhtml11-20070216/conformance.html#strict>
13
1975
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 populate the XML. In general I think I know how to create elements and attributes and I'm sure I can hack something together but I'm wondering if I'm missing (or forgetting) a better way (other than a long line of hard-coded CreateElement commands)....
2
1969
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 having a problem converting document.write() statements which are not allowed in XHTML documents to statements which create the DOM nodes/elements dynamically within script elements.
0
9715
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9595
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10600
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10352
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10097
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7642
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5535
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5673
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.