W3C home > Mailing lists > Public > www-validator@w3.org > July 2010

Re: Validator fails on PHP instructions inside attribute values

From: Dag-Erling Smørgrav <des@des.no>
Date: Wed, 21 Jul 2010 12:52:33 +0200
To: "Philip Taylor \(Webmaster\, Ret'd\)" <P.Taylor@Rhul.Ac.Uk>
Cc: Richard Ishida <ishida@w3.org>, 'David Dorward' <david@dorward.me.uk>, www-validator@w3.org
Message-ID: <86oce1qf7y.fsf@ds4.des.no>
"Philip Taylor (Webmaster, Ret'd)" <P.Taylor@Rhul.Ac.Uk> writes:
> I think there is a better solution : write a custom DTD that extends
> the DOCTYPE against which you are trying to validate by making all
> well-formed constructs of the form
> 	<?php echo $clang;?>
> legal within attribute values and anywhere else that you wish to use
> them but which do not satisfy the formal requirements for a Processing
> Instruction (PI), then validate against that DTD.

Regardless of DTD, you can't have unescaped angle brackets inside
attribute values; nor can you write a DTD that makes <?php ...?>
something else than a PI or allows its use in places where a PI is not

<?php ...?> is a well-formed PI and will be ignored by processors that
do not understand it as long as it is used only where a PI is permitted;
I gave a complete list in an earlier reply.

This means you can't do something like

 <?php if (red) {?>
 <p style="color: red">
 <?php } else {?>
 <p style="color: black">
 <?php }?>

because anything other than PHP will ignore the <?php ...?> bits and see

 <p style="color: red">
 <p style="color: black">

which is not well-formed XML.

Dag-Erling Smørgrav - des@des.no
Received on Wednesday, 21 July 2010 10:53:08 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 1 March 2016 14:18:01 UTC