XML. Prevent < from turning into &lt;

XML. Prevent < from turning into &lt;

am 09.09.2009 11:27:54 von Matthew Croud

Hiya,
I'm writing an app that let's my client upload images, the image html
code is added to an XML file.
Take a look at the element below:


e1022
Image" width="124" height="70" />]]>
Blue Ski Trousers
8.99


Now, whenever PHP writes this to the XML files, it turns the < and >
into < and > . which means it does not display on the webpage.
How can I prevent this from happening ?

Many thanks,
Matt


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: XML. Prevent < from turning into &lt;

am 09.09.2009 15:26:42 von Phpster

On Wed, Sep 9, 2009 at 5:27 AM, Matthew Croud wrot=
e:
>
> Hiya,
> I'm writing an app that let's my client upload images, the image html cod=
e
> is added to an XML file.
> Take a look at the element below:
>
>
> =A0 =A0e1022
> =A0 =A0 age"
> width=3D"124" height=3D"70" />]]>
> =A0 =A0Blue Ski Trousers
> =A0 =A08.99
> =A0

>
> Now, whenever PHP writes this to the XML files, it turns the < and > into
> < and > . which means it does not display on the webpage. =A0How ca=
n I
> prevent this from happening ?
>
> Many thanks,
> Matt
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

str_replace?


--=20

Bastien

Cat, the other other white meat

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: XML. Prevent < from turning into &lt;

am 09.09.2009 15:33:30 von Matthew Croud

On 9 Sep 2009, at 14:26, Bastien Koert wrote:

> On Wed, Sep 9, 2009 at 5:27 AM, Matthew
> Croud wrote:
>>
>> Hiya,
>> I'm writing an app that let's my client upload images, the image
>> html code
>> is added to an XML file.
>> Take a look at the element below:
>>
>>
>> e1022
>> >> width="124" height="70" />]]>
>> Blue Ski Trousers
>> 8.99
>>

>>
>> Now, whenever PHP writes this to the XML files, it turns the < and
>> > into
>> < and > . which means it does not display on the webpage.
>> How can I
>> prevent this from happening ?
>>
>> Many thanks,
>> Matt
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> str_replace?
>
>
> --
>
> Bastien
>
> Cat, the other other white meat


I've tried that but no matter what i do in the PHP side of things, as
soon as I save that XML the conversion takes place.
Should the XML be encoded in any way, is there a setting somewhere
that prevents this ?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

RE: XML. Prevent < from turning into &lt;

am 09.09.2009 15:36:42 von Bob McConnell

From: Bastien Koert
> On Wed, Sep 9, 2009 at 5:27 AM, Matthew Croud =
wrote:
>>
>> Hiya,
>> I'm writing an app that let's my client upload images, the image html =
code
>> is added to an XML file.
>> Take a look at the element below:
>>
>>
>> =A0 =A0e1022
>> =A0 =A0 alt=3D"Homepage Image"
>> width=3D"124" height=3D"70" />]]>
>> =A0 =A0Blue Ski Trousers
>> =A0 =A08.99
>> =A0

>>
>> Now, whenever PHP writes this to the XML files, it turns the < and > =
into
>> < and > . which means it does not display on the webpage. =
=A0How can I
>> prevent this from happening ?
>>
>=20
> str_replace?
>=20

Does the xml string get passed to htmlentities() or a similar function =
before it is sent to the browser? That would explain the substitutions. =
I saw an xmlentities() variation mentioned somewhere.

Bob McConnell

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: XML. Prevent < from turning into &lt;

am 09.09.2009 15:41:07 von Eddie Drapkin

On Wed, Sep 9, 2009 at 9:33 AM, Matthew Croud wro=
te:
>
> On 9 Sep 2009, at 14:26, Bastien Koert wrote:
>
>> On Wed, Sep 9, 2009 at 5:27 AM, Matthew Croud
>> wrote:
>>>
>>> Hiya,
>>> I'm writing an app that let's my client upload images, the image html
>>> code
>>> is added to an XML file.
>>> Take a look at the element below:
>>>
>>>
>>>   e1022
>>>   Image"
>>> width=3D"124" height=3D"70" />]]>
>>>   Blue Ski Trousers
>>>   8.99
>>>  

>>>
>>> Now, whenever PHP writes this to the XML files, it turns the < and > in=
to
>>> < and > . which means it does not display on the webpage.  H=
ow can
>>> I
>>> prevent this from happening ?
>>>
>>> Many thanks,
>>> Matt
>>>
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>
>> str_replace?
>>
>>
>> --
>>
>> Bastien
>>
>> Cat, the other other white meat
>
>
> I've tried that but no matter what i do in the PHP side of things, as soo=
n
> as I save that XML the conversion takes place.
> Should the XML be encoded in any way, is there a setting somewhere that
> prevents this ?
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Perhaps you'd be so kind as to share with us what code you're using to
generate the erroneous XML?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: XML. Prevent < from turning into &lt;

am 09.09.2009 15:46:40 von Matthew Croud

--Apple-Mail-11--681105995
Content-Type: text/plain;
charset=US-ASCII;
format=flowed;
delsp=yes
Content-Transfer-Encoding: 7bit


On 9 Sep 2009, at 14:36, Bob McConnell wrote:

> From: Bastien Koert
>> On Wed, Sep 9, 2009 at 5:27 AM, Matthew
>> Croud wrote:
>>>
>>> Hiya,
>>> I'm writing an app that let's my client upload images, the image
>>> html code
>>> is added to an XML file.
>>> Take a look at the element below:
>>>
>>>
>>> e1022
>>> >>> Image"
>>> width="124" height="70" />]]>
>>> Blue Ski Trousers
>>> 8.99
>>>

>>>
>>> Now, whenever PHP writes this to the XML files, it turns the < and
>>> > into
>>> < and > . which means it does not display on the webpage.
>>> How can I
>>> prevent this from happening ?
>>>
>>
>> str_replace?
>>
>
> Does the xml string get passed to htmlentities() or a similar
> function before it is sent to the browser? That would explain the
> substitutions. I saw an xmlentities() variation mentioned somewhere.
>
> Bob McConnell
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


Hi Bob,

Nope the string doesn't get passed into any function.
Here is the XML:
____________________________________________________________ _____





e1021
Image" width="124" height="70" border="1"
onclick="MM_openBrWindow('uploads/
image1.jpg','Preview','width=680,height=520')" />]]>
Red Jacket
An adult sized red jacket
adult
12.99



e1022
Image" width="124" height="70" border="1"
onclick="MM_openBrWindow('uploads/
image2.jpg','Preview','width=680,height=520')" />]]>
Blue Ski Trousers
A pair of Blue Ski Trousers
child
8.99




____________________________________________________________ ____

Now the image tags I have written here I have done manually, but when
I use PHP using DOM they come out like this (note the image element):


e1024
<![CDATA[<img src="uploads/image4.jpg" alt="Homepage
Image" width="124" height="70" border="1"
onclick="MM_openBrWindow('uploads/
image4.jpg','Preview','width=680,height=520')" />]]>
orange top
an orange jacket
large
14.50





Matthew Croud
Studio

Obvious Print Solutions Limited
Unit 3 Abbeygate Court
Stockett Lane
Maidstone
Kent
ME15 0PP

T | 0845 094 9704
F | 0845 094 9705
www.obviousprint.com






--Apple-Mail-11--681105995--

Re: XML. Prevent < from turning into &lt;

am 09.09.2009 16:09:23 von Ashley Sheridan

On Wed, 2009-09-09 at 14:46 +0100, Matthew Croud wrote:
> On 9 Sep 2009, at 14:36, Bob McConnell wrote:
>
> > From: Bastien Koert
> >> On Wed, Sep 9, 2009 at 5:27 AM, Matthew
> >> Croud wrote:
> >>>
> >>> Hiya,
> >>> I'm writing an app that let's my client upload images, the image
> >>> html code
> >>> is added to an XML file.
> >>> Take a look at the element below:
> >>>
> >>>
> >>> e1022
> >>> > >>> Image"
> >>> width="124" height="70" />]]>
> >>> Blue Ski Trousers
> >>> 8.99
> >>>

> >>>
> >>> Now, whenever PHP writes this to the XML files, it turns the < and
> >>> > into
> >>> < and > . which means it does not display on the webpage.
> >>> How can I
> >>> prevent this from happening ?
> >>>
> >>
> >> str_replace?
> >>
> >
> > Does the xml string get passed to htmlentities() or a similar
> > function before it is sent to the browser? That would explain the
> > substitutions. I saw an xmlentities() variation mentioned somewhere.
> >
> > Bob McConnell
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
>
>
> Hi Bob,
>
> Nope the string doesn't get passed into any function.
> Here is the XML:
> ____________________________________________________________ _____
>
>
>
>
>
> e1021
> > Image" width="124" height="70" border="1"
> onclick="MM_openBrWindow('uploads/
> image1.jpg','Preview','width=680,height=520')" />]]>
> Red Jacket
> An adult sized red jacket
> adult
> 12.99
>

>
>
> e1022
> > Image" width="124" height="70" border="1"
> onclick="MM_openBrWindow('uploads/
> image2.jpg','Preview','width=680,height=520')" />]]>
> Blue Ski Trousers
> A pair of Blue Ski Trousers
> child
> 8.99
>

>
>

>
> ____________________________________________________________ ____
>
> Now the image tags I have written here I have done manually, but when
> I use PHP using DOM they come out like this (note the image element):
>
>
> e1024
> <![CDATA[<img src="uploads/image4.jpg" alt="Homepage
> Image" width="124" height="70" border="1"
> onclick="MM_openBrWindow('uploads/
> image4.jpg','Preview','width=680,height=520')" />]]>
> orange top
> an orange jacket
> large
> 14.50
>

>
>
>
>
> Matthew Croud
> Studio
>
> Obvious Print Solutions Limited
> Unit 3 Abbeygate Court
> Stockett Lane
> Maidstone
> Kent
> ME15 0PP
>
> T | 0845 094 9704
> F | 0845 094 9705
> www.obviousprint.com
>
>
>
>
>
I've not experienced this with using any DOM functions, but if we can
see your code it might help us.

Thanks,
Ash
http://www.ashleysheridan.co.uk




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Re: XML. Prevent < from turning into &lt;

am 09.09.2009 17:51:52 von Matthew Croud

On 9 Sep 2009, at 16:37, Ashley Sheridan wrote:

> On Wed, 2009-09-09 at 15:14 +0100, Matthew Croud wrote:
>> On 9 Sep 2009, at 15:09, Ashley Sheridan wrote:
>>
>>> On Wed, 2009-09-09 at 14:46 +0100, Matthew Croud wrote:
>>>> On 9 Sep 2009, at 14:36, Bob McConnell wrote:
>>>>
>>>>> From: Bastien Koert
>>>>>> On Wed, Sep 9, 2009 at 5:27 AM, Matthew
>>>>>> Croud wrote:
>>>>>>>
>>>>>>> Hiya,
>>>>>>> I'm writing an app that let's my client upload images, the image
>>>>>>> html code
>>>>>>> is added to an XML file.
>>>>>>> Take a look at the element below:
>>>>>>>
>>>>>>>
>>>>>>> e1022
>>>>>>> >>>>>>> Image"
>>>>>>> width="124" height="70" />]]>
>>>>>>> Blue Ski Trousers
>>>>>>> 8.99
>>>>>>>

>>>>>>>
>>>>>>> Now, whenever PHP writes this to the XML files, it turns the <
>>>>>>> and
>>>>>>>> into
>>>>>>> < and > . which means it does not display on the webpage.
>>>>>>> How can I
>>>>>>> prevent this from happening ?
>>>>>>>
>>>>>>
>>>>>> str_replace?
>>>>>>
>>>>>
>>>>> Does the xml string get passed to htmlentities() or a similar
>>>>> function before it is sent to the browser? That would explain the
>>>>> substitutions. I saw an xmlentities() variation mentioned
>>>>> somewhere.
>>>>>
>>>>> Bob McConnell
>>>>>
>>>>> --
>>>>> PHP General Mailing List (http://www.php.net/)
>>>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>>>
>>>>
>>>>
>>>> Hi Bob,
>>>>
>>>> Nope the string doesn't get passed into any function.
>>>> Here is the XML:
>>>> ____________________________________________________________ _____
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> e1021
>>>> >>>> Image" width="124" height="70" border="1"
>>>> onclick="MM_openBrWindow('uploads/
>>>> image1.jpg','Preview','width=680,height=520')" />]]>
>>>> Red Jacket
>>>> An adult sized red jacket
>>>> adult
>>>> 12.99
>>>>

>>>>
>>>>
>>>> e1022
>>>> >>>> Image" width="124" height="70" border="1"
>>>> onclick="MM_openBrWindow('uploads/
>>>> image2.jpg','Preview','width=680,height=520')" />]]>
>>>> Blue Ski Trousers
>>>> A pair of Blue Ski Trousers
>>>> child
>>>> 8.99
>>>>

>>>>
>>>>

>>>>
>>>> ____________________________________________________________ ____
>>>>
>>>> Now the image tags I have written here I have done manually, but
>>>> when
>>>> I use PHP using DOM they come out like this (note the image
>>>> element):
>>>>
>>>>
>>>> e1024
>>>> <![CDATA[<img src="uploads/image4.jpg" alt="Homepage
>>>> Image" width="124" height="70" border="1"
>>>> onclick="MM_openBrWindow('uploads/
>>>> image4.jpg','Preview','width=680,height=520')" />]]>
>>>> orange top
>>>> an orange jacket
>>>> large
>>>> 14.50
>>>>

>>>>
>>>>
>>>>
>>>>
>>>> Matthew Croud
>>>> Studio
>>>>
>>>> Obvious Print Solutions Limited
>>>> Unit 3 Abbeygate Court
>>>> Stockett Lane
>>>> Maidstone
>>>> Kent
>>>> ME15 0PP
>>>>
>>>> T | 0845 094 9704
>>>> F | 0845 094 9705
>>>> www.obviousprint.com
>>>>
>>>>
>>>>
>>>>
>>>>
>>> I've not experienced this with using any DOM functions, but if we
>>> can
>>> see your code it might help us.
>>>
>>> Thanks,
>>> Ash
>>> http://www.ashleysheridan.co.uk
>>>
>>>
>>>
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>
>>
>>
>>
>> Well i'll pop the PHP down here, i'll trim it as much as i can:
>> ____________________________________________________________ ____________
>>
>> $code = $_POST['code'];
>> $name = $_POST['name'];
>> $desc = $_POST['desc'];
>> $size = $_POST['size'];
>> $price = $_POST['price'];
>>
>>
>> #load an XML document into the DOM
>>
>> $dom = new DomDocument();
>> $dom -> load("items.xml");
>>
>> #create elements
>>
>> $Xitem = $dom -> createElement("item");
>> $Xcode = $dom -> createElement("code");
>> $Ximage = $dom -> createElement("image");
>> $Xname = $dom -> createElement("name");
>> $Xdesc = $dom -> createElement("desc");
>> $Xsize = $dom -> createElement("size");
>> $Xprice = $dom -> createElement("price");
>>
>> #create text nodes
>>
>> $Xcodetext = $dom -> createTextNode($code);
>> $Ximagetext = $dom -> createTextNode( " >> $UploadName\" alt=\"Homepage Image\" width=\"124\" height=\"70\"
>> border=\"1\" onclick=\"MM_openBrWindow('uploads/
>> $UploadName','Preview','width=680,height=520')\" />]]>" );
>> $Xnametext = $dom -> createTextNode($name);
>> $Xdesctext = $dom -> createTextNode($desc);
>> $Xsizetext = $dom -> createTextNode($size);
>> $Xpricetext = $dom -> createTextNode($price);
>>
>> #append the text nodes to the inner nested elements
>>
>> $Xcode -> appendChild($Xcodetext);
>> $Ximage -> appendChild($Ximagetext);
>> $Xname -> appendChild($Xnametext);
>> $Xdesc -> appendChild($Xdesctext);
>> $Xsize -> appendChild($Xsizetext);
>> $Xprice -> appendChild($Xpricetext);
>>
>> #append the inner nested elements to the element
>>
>> $Xitem -> appendChild($Xcode);
>> $Xitem -> appendChild($Ximage);
>> $Xitem -> appendChild($Xname);
>> $Xitem -> appendChild($Xdesc);
>> $Xitem -> appendChild($Xsize);
>> $Xitem -> appendChild($Xprice);
>> $Xitem -> setAttribute("Code",$code);
>>
>> #append the element to the root element<br /> >><br /> >> $dom -> documentElement -> appendChild($Xitem);<br /> >><br /> >> #create a new enlarged xml document<br /> >><br /> >> $dom -> save("items.xml");<br /> >><br /> >> _____________________________________________________<br /> > It looks like it's because you are creating an image object by <br /> > appending<br /> > a text node inside CDATA to it. My guess is that a text node will have<br /> > the contents automatically made 'safe' for the XML entities which <br /> > are <,<br /> >> , &, etc.<br /> ><br /> > Why are you appending the child item like this? What's wrong with <br /> > adding<br /> > it as a proper object, attributes and all?<br /> ><br /> > Thanks,<br /> > Ash<br /> > http://www.ashleysheridan.co.uk<br /> ><br /> ><br /> ><br /> <br /> <br /> Hi Ash,<br /> <br /> Thanks for getting back to me,<br /> In all honesty this method is what's implemented in the course book <br /> i've been following.<br /> <br /> I been using XML longer and i've never had this issue using image tags <br /> before and getting the output I expected.<br /> Is there a way around this safety mechanism ? Otherwise i'll have to <br /> think of another way of doing this.<br /> <br /> Cheers.<br /> <br /> -- <br /> PHP General Mailing List (http://www.php.net/)<br /> To unsubscribe, visit: http://www.php.net/unsub.php</p> </article> <article> <h2>Re: XML. Prevent < from turning into &lt;</h2><span>am 09.09.2009 18:04:12 von Ashley Sheridan</span> <p>On Wed, 2009-09-09 at 16:51 +0100, Matthew Croud wrote:<br /> > On 9 Sep 2009, at 16:37, Ashley Sheridan wrote:<br /> > <br /> > > On Wed, 2009-09-09 at 15:14 +0100, Matthew Croud wrote:<br /> > >> On 9 Sep 2009, at 15:09, Ashley Sheridan wrote:<br /> > >><br /> > >>> On Wed, 2009-09-09 at 14:46 +0100, Matthew Croud wrote:<br /> > >>>> On 9 Sep 2009, at 14:36, Bob McConnell wrote:<br /> > >>>><br /> > >>>>> From: Bastien Koert<br /> > >>>>>> On Wed, Sep 9, 2009 at 5:27 AM, Matthew<br /> > >>>>>> Croud<matt@obviousdigital.com> wrote:<br /> > >>>>>>><br /> > >>>>>>> Hiya,<br /> > >>>>>>> I'm writing an app that let's my client upload images, the image<br /> > >>>>>>> html code<br /> > >>>>>>> is added to an XML file.<br /> > >>>>>>> Take a look at the <image> element below:<br /> > >>>>>>><br /> > >>>>>>> <item Code="e1022"><br /> > >>>>>>> <code>e1022</code><br /> > >>>>>>> <image><![CDATA[<img src="uploads/image2.jpg" alt="Homepage<br /> > >>>>>>> Image"<br /> > >>>>>>> width="124" height="70" />]]></image><br /> > >>>>>>> <name>Blue Ski Trousers</name><br /> > >>>>>>> <price>8.99</price><br /> > >>>>>>> </item><br /> > >>>>>>><br /> > >>>>>>> Now, whenever PHP writes this to the XML files, it turns the < <br /> > >>>>>>> and<br /> > >>>>>>>> into<br /> > >>>>>>> < and > . which means it does not display on the webpage.<br /> > >>>>>>> How can I<br /> > >>>>>>> prevent this from happening ?<br /> > >>>>>>><br /> > >>>>>><br /> > >>>>>> str_replace?<br /> > >>>>>><br /> > >>>>><br /> > >>>>> Does the xml string get passed to htmlentities() or a similar<br /> > >>>>> function before it is sent to the browser? That would explain the<br /> > >>>>> substitutions. I saw an xmlentities() variation mentioned <br /> > >>>>> somewhere.<br /> > >>>>><br /> > >>>>> Bob McConnell<br /> > >>>>><br /> > >>>>> --<br /> > >>>>> PHP General Mailing List (http://www.php.net/)<br /> > >>>>> To unsubscribe, visit: http://www.php.net/unsub.php<br /> > >>>>><br /> > >>>><br /> > >>>><br /> > >>>> Hi Bob,<br /> > >>>><br /> > >>>> Nope the string doesn't get passed into any function.<br /> > >>>> Here is the XML:<br /> > >>>> ____________________________________________________________ _____<br /> > >>>><br /> > >>>> <?xml version="1.0" encoding="UTF-8"?><br /> > >>>> <clothes><br /> > >>>><br /> > >>>> <item Code="e1021"><br /> > >>>> <code>e1021</code><br /> > >>>> <image><![CDATA[<img src="uploads/image1.jpg" alt="Homepage<br /> > >>>> Image" width="124" height="70" border="1"<br /> > >>>> onclick="MM_openBrWindow('uploads/<br /> > >>>> image1.jpg','Preview','width=680,height=520')" />]]></image><br /> > >>>> <name>Red Jacket</name><br /> > >>>> <desc>An adult sized red jacket</desc><br /> > >>>> <size>adult</size><br /> > >>>> <price>12.99</price><br /> > >>>> </item><br /> > >>>><br /> > >>>> <item Code="e1022"><br /> > >>>> <code>e1022</code><br /> > >>>> <image><![CDATA[<img src="uploads/image2.jpg" alt="Homepage<br /> > >>>> Image" width="124" height="70" border="1"<br /> > >>>> onclick="MM_openBrWindow('uploads/<br /> > >>>> image2.jpg','Preview','width=680,height=520')" />]]></image><br /> > >>>> <name>Blue Ski Trousers</name><br /> > >>>> <desc>A pair of Blue Ski Trousers</desc><br /> > >>>> <size>child</size><br /> > >>>> <price>8.99</price><br /> > >>>> </item><br /> > >>>><br /> > >>>> </clothes><br /> > >>>><br /> > >>>> ____________________________________________________________ ____<br /> > >>>><br /> > >>>> Now the image tags I have written here I have done manually, but <br /> > >>>> when<br /> > >>>> I use PHP using DOM they come out like this (note the image <br /> > >>>> element):<br /> > >>>><br /> > >>>> <item Code="e1024"><br /> > >>>> <code>e1024</code><br /> > >>>> <image><![CDATA[<img src="uploads/image4.jpg" alt="Homepage<br /> > >>>> Image" width="124" height="70" border="1"<br /> > >>>> onclick="MM_openBrWindow('uploads/<br /> > >>>> image4.jpg','Preview','width=680,height=520')" />]]></image><br /> > >>>> <name>orange top</name><br /> > >>>> <desc>an orange jacket</desc><br /> > >>>> <size>large</size><br /> > >>>> <price>14.50</price><br /> > >>>> </item><br /> > >>>><br /> > >>>><br /> > >>>><br /> > >>>><br /> > >>>> Matthew Croud<br /> > >>>> Studio<br /> > >>>><br /> > >>>> Obvious Print Solutions Limited<br /> > >>>> Unit 3 Abbeygate Court<br /> > >>>> Stockett Lane<br /> > >>>> Maidstone<br /> > >>>> Kent<br /> > >>>> ME15 0PP<br /> > >>>><br /> > >>>> T | 0845 094 9704<br /> > >>>> F | 0845 094 9705<br /> > >>>> www.obviousprint.com<br /> > >>>><br /> > >>>><br /> > >>>><br /> > >>>><br /> > >>>><br /> > >>> I've not experienced this with using any DOM functions, but if we <br /> > >>> can<br /> > >>> see your code it might help us.<br /> > >>><br /> > >>> Thanks,<br /> > >>> Ash<br /> > >>> http://www.ashleysheridan.co.uk<br /> > >>><br /> > >>><br /> > >>><br /> > >>><br /> > >>> -- <br /> > >>> PHP General Mailing List (http://www.php.net/)<br /> > >>> To unsubscribe, visit: http://www.php.net/unsub.php<br /> > >>><br /> > >><br /> > >><br /> > >><br /> > >><br /> > >> Well i'll pop the PHP down here, i'll trim it as much as i can:<br /> > >> ____________________________________________________________ ____________<br /> > >><br /> > >> $code = $_POST['code'];<br /> > >> $name = $_POST['name'];<br /> > >> $desc = $_POST['desc'];<br /> > >> $size = $_POST['size'];<br /> > >> $price = $_POST['price'];<br /> > >><br /> > >><br /> > >> #load an XML document into the DOM<br /> > >><br /> > >> $dom = new DomDocument();<br /> > >> $dom -> load("items.xml");<br /> > >><br /> > >> #create elements<br /> > >><br /> > >> $Xitem = $dom -> createElement("item");<br /> > >> $Xcode = $dom -> createElement("code");<br /> > >> $Ximage = $dom -> createElement("image");<br /> > >> $Xname = $dom -> createElement("name");<br /> > >> $Xdesc = $dom -> createElement("desc");<br /> > >> $Xsize = $dom -> createElement("size");<br /> > >> $Xprice = $dom -> createElement("price");<br /> > >><br /> > >> #create text nodes<br /> > >><br /> > >> $Xcodetext = $dom -> createTextNode($code);<br /> > >> $Ximagetext = $dom -> createTextNode( "<![CDATA[<img src=\"uploads/<br /> > >> $UploadName\" alt=\"Homepage Image\" width=\"124\" height=\"70\"<br /> > >> border=\"1\" onclick=\"MM_openBrWindow('uploads/<br /> > >> $UploadName','Preview','width=680,height=520')\" />]]>" );<br /> > >> $Xnametext = $dom -> createTextNode($name);<br /> > >> $Xdesctext = $dom -> createTextNode($desc);<br /> > >> $Xsizetext = $dom -> createTextNode($size);<br /> > >> $Xpricetext = $dom -> createTextNode($price);<br /> > >><br /> > >> #append the text nodes to the inner nested elements<br /> > >><br /> > >> $Xcode -> appendChild($Xcodetext);<br /> > >> $Ximage -> appendChild($Ximagetext);<br /> > >> $Xname -> appendChild($Xnametext);<br /> > >> $Xdesc -> appendChild($Xdesctext);<br /> > >> $Xsize -> appendChild($Xsizetext);<br /> > >> $Xprice -> appendChild($Xpricetext);<br /> > >><br /> > >> #append the inner nested elements to the <item> element<br /> > >><br /> > >> $Xitem -> appendChild($Xcode);<br /> > >> $Xitem -> appendChild($Ximage);<br /> > >> $Xitem -> appendChild($Xname);<br /> > >> $Xitem -> appendChild($Xdesc);<br /> > >> $Xitem -> appendChild($Xsize);<br /> > >> $Xitem -> appendChild($Xprice);<br /> > >> $Xitem -> setAttribute("Code",$code);<br /> > >><br /> > >> #append the <title> element to the root element<br /> > >><br /> > >> $dom -> documentElement -> appendChild($Xitem);<br /> > >><br /> > >> #create a new enlarged xml document<br /> > >><br /> > >> $dom -> save("items.xml");<br /> > >><br /> > >> _____________________________________________________<br /> > > It looks like it's because you are creating an image object by <br /> > > appending<br /> > > a text node inside CDATA to it. My guess is that a text node will have<br /> > > the contents automatically made 'safe' for the XML entities which <br /> > > are <,<br /> > >> , &, etc.<br /> > ><br /> > > Why are you appending the child item like this? What's wrong with <br /> > > adding<br /> > > it as a proper object, attributes and all?<br /> > ><br /> > > Thanks,<br /> > > Ash<br /> > > http://www.ashleysheridan.co.uk<br /> > ><br /> > ><br /> > ><br /> > <br /> > <br /> > Hi Ash,<br /> > <br /> > Thanks for getting back to me,<br /> > In all honesty this method is what's implemented in the course book <br /> > i've been following.<br /> > <br /> > I been using XML longer and i've never had this issue using image tags <br /> > before and getting the output I expected.<br /> > Is there a way around this safety mechanism ? Otherwise i'll have to <br /> > think of another way of doing this.<br /> > <br /> > Cheers.<br /> > <br /> <br /> Just create the image tag using the same methods as you're creating the<br /> other nodes. So the image object would contain several attribute nodes,<br /> but would have no regular child nodes of its own.<br /> <br /> Thanks,<br /> Ash<br /> http://www.ashleysheridan.co.uk<br /> <br /> <br /> <br /> <br /> -- <br /> PHP General Mailing List (http://www.php.net/)<br /> To unsubscribe, visit: http://www.php.net/unsub.php</p> </article> <article> <h2>Re: XML. Prevent < from turning into &lt;</h2><span>am 09.09.2009 18:07:21 von Tony Marston</span> <p>You need to look at "disable_output_escaping" at <br /> http://www.w3.org/TR/xslt#disable-output-escaping<br /> <br /> -- <br /> Tony Marston<br /> http://www.tonymarston.net<br /> http://www.radicore.org<br /> <br /> "Matthew Croud" <matt@obviousdigital.com> wrote in message <br /> news:2C4840C2-45DB-4D6C-B5FA-2CB15B1716A5@obviousdigital.com ...<br /> ><br /> > On 9 Sep 2009, at 14:26, Bastien Koert wrote:<br /> ><br /> >> On Wed, Sep 9, 2009 at 5:27 AM, Matthew Croud<matt@obviousdigital.com> <br /> >> wrote:<br /> >>><br /> >>> Hiya,<br /> >>> I'm writing an app that let's my client upload images, the image html <br /> >>> code<br /> >>> is added to an XML file.<br /> >>> Take a look at the <image> element below:<br /> >>><br /> >>> <item Code="e1022"><br /> >>> <code>e1022</code><br /> >>> <image><![CDATA[<img src="uploads/image2.jpg" alt="Homepage Image"<br /> >>> width="124" height="70" />]]></image><br /> >>> <name>Blue Ski Trousers</name><br /> >>> <price>8.99</price><br /> >>> </item><br /> >>><br /> >>> Now, whenever PHP writes this to the XML files, it turns the < and<br /> >>> > into<br /> >>> < and > . which means it does not display on the webpage. How <br /> >>> can I<br /> >>> prevent this from happening ?<br /> >>><br /> >>> Many thanks,<br /> >>> Matt<br /> >>><br /> >>><br /> >>> --<br /> >>> PHP General Mailing List (http://www.php.net/)<br /> >>> To unsubscribe, visit: http://www.php.net/unsub.php<br /> >>><br /> >>><br /> >><br /> >> str_replace?<br /> >><br /> >><br /> >> -- <br /> >><br /> >> Bastien<br /> >><br /> >> Cat, the other other white meat<br /> ><br /> ><br /> > I've tried that but no matter what i do in the PHP side of things, as <br /> > soon as I save that XML the conversion takes place.<br /> > Should the XML be encoded in any way, is there a setting somewhere that <br /> > prevents this ? <br /> <br /> <br /> <br /> -- <br /> PHP General Mailing List (http://www.php.net/)<br /> To unsubscribe, visit: http://www.php.net/unsub.php</p> </article> <article> <h2>Re: XML. Prevent < from turning into &lt;</h2><span>am 09.09.2009 21:03:42 von Ralph Deffke</span> <p>give it a try with PDATA instead of CDATA and see what happns<br /> <br /> <br /> "Ashley Sheridan" <ash@ashleysheridan.co.uk> wrote in message<br /> news:1252512252.2961.40.camel@localhost...<br /> > On Wed, 2009-09-09 at 16:51 +0100, Matthew Croud wrote:<br /> > > On 9 Sep 2009, at 16:37, Ashley Sheridan wrote:<br /> > ><br /> > > > On Wed, 2009-09-09 at 15:14 +0100, Matthew Croud wrote:<br /> > > >> On 9 Sep 2009, at 15:09, Ashley Sheridan wrote:<br /> > > >><br /> > > >>> On Wed, 2009-09-09 at 14:46 +0100, Matthew Croud wrote:<br /> > > >>>> On 9 Sep 2009, at 14:36, Bob McConnell wrote:<br /> > > >>>><br /> > > >>>>> From: Bastien Koert<br /> > > >>>>>> On Wed, Sep 9, 2009 at 5:27 AM, Matthew<br /> > > >>>>>> Croud<matt@obviousdigital.com> wrote:<br /> > > >>>>>>><br /> > > >>>>>>> Hiya,<br /> > > >>>>>>> I'm writing an app that let's my client upload images, the image<br /> > > >>>>>>> html code<br /> > > >>>>>>> is added to an XML file.<br /> > > >>>>>>> Take a look at the <image> element below:<br /> > > >>>>>>><br /> > > >>>>>>> <item Code="e1022"><br /> > > >>>>>>> <code>e1022</code><br /> > > >>>>>>> <image><![CDATA[<img src="uploads/image2.jpg" alt="Homepage<br /> > > >>>>>>> Image"<br /> > > >>>>>>> width="124" height="70" />]]></image><br /> > > >>>>>>> <name>Blue Ski Trousers</name><br /> > > >>>>>>> <price>8.99</price><br /> > > >>>>>>> </item><br /> > > >>>>>>><br /> > > >>>>>>> Now, whenever PHP writes this to the XML files, it turns the <<br /> > > >>>>>>> and<br /> > > >>>>>>>> into<br /> > > >>>>>>> < and > . which means it does not display on the webpage.<br /> > > >>>>>>> How can I<br /> > > >>>>>>> prevent this from happening ?<br /> > > >>>>>>><br /> > > >>>>>><br /> > > >>>>>> str_replace?<br /> > > >>>>>><br /> > > >>>>><br /> > > >>>>> Does the xml string get passed to htmlentities() or a similar<br /> > > >>>>> function before it is sent to the browser? That would explain the<br /> > > >>>>> substitutions. I saw an xmlentities() variation mentioned<br /> > > >>>>> somewhere.<br /> > > >>>>><br /> > > >>>>> Bob McConnell<br /> > > >>>>><br /> > > >>>>> --<br /> > > >>>>> PHP General Mailing List (http://www.php.net/)<br /> > > >>>>> To unsubscribe, visit: http://www.php.net/unsub.php<br /> > > >>>>><br /> > > >>>><br /> > > >>>><br /> > > >>>> Hi Bob,<br /> > > >>>><br /> > > >>>> Nope the string doesn't get passed into any function.<br /> > > >>>> Here is the XML:<br /> > > >>>> ____________________________________________________________ _____<br /> > > >>>><br /> > > >>>> <?xml version="1.0" encoding="UTF-8"?><br /> > > >>>> <clothes><br /> > > >>>><br /> > > >>>> <item Code="e1021"><br /> > > >>>> <code>e1021</code><br /> > > >>>> <image><![CDATA[<img src="uploads/image1.jpg" alt="Homepage<br /> > > >>>> Image" width="124" height="70" border="1"<br /> > > >>>> onclick="MM_openBrWindow('uploads/<br /> > > >>>> image1.jpg','Preview','width=680,height=520')" />]]></image><br /> > > >>>> <name>Red Jacket</name><br /> > > >>>> <desc>An adult sized red jacket</desc><br /> > > >>>> <size>adult</size><br /> > > >>>> <price>12.99</price><br /> > > >>>> </item><br /> > > >>>><br /> > > >>>> <item Code="e1022"><br /> > > >>>> <code>e1022</code><br /> > > >>>> <image><![CDATA[<img src="uploads/image2.jpg" alt="Homepage<br /> > > >>>> Image" width="124" height="70" border="1"<br /> > > >>>> onclick="MM_openBrWindow('uploads/<br /> > > >>>> image2.jpg','Preview','width=680,height=520')" />]]></image><br /> > > >>>> <name>Blue Ski Trousers</name><br /> > > >>>> <desc>A pair of Blue Ski Trousers</desc><br /> > > >>>> <size>child</size><br /> > > >>>> <price>8.99</price><br /> > > >>>> </item><br /> > > >>>><br /> > > >>>> </clothes><br /> > > >>>><br /> > > >>>> ____________________________________________________________ ____<br /> > > >>>><br /> > > >>>> Now the image tags I have written here I have done manually, but<br /> > > >>>> when<br /> > > >>>> I use PHP using DOM they come out like this (note the image<br /> > > >>>> element):<br /> > > >>>><br /> > > >>>> <item Code="e1024"><br /> > > >>>> <code>e1024</code><br /> > > >>>> <image><![CDATA[<img src="uploads/image4.jpg" alt="Homepage<br /> > > >>>> Image" width="124" height="70" border="1"<br /> > > >>>> onclick="MM_openBrWindow('uploads/<br /> > > >>>> image4.jpg','Preview','width=680,height=520')" />]]></image><br /> > > >>>> <name>orange top</name><br /> > > >>>> <desc>an orange jacket</desc><br /> > > >>>> <size>large</size><br /> > > >>>> <price>14.50</price><br /> > > >>>> </item><br /> > > >>>><br /> > > >>>><br /> > > >>>><br /> > > >>>><br /> > > >>>> Matthew Croud<br /> > > >>>> Studio<br /> > > >>>><br /> > > >>>> Obvious Print Solutions Limited<br /> > > >>>> Unit 3 Abbeygate Court<br /> > > >>>> Stockett Lane<br /> > > >>>> Maidstone<br /> > > >>>> Kent<br /> > > >>>> ME15 0PP<br /> > > >>>><br /> > > >>>> T | 0845 094 9704<br /> > > >>>> F | 0845 094 9705<br /> > > >>>> www.obviousprint.com<br /> > > >>>><br /> > > >>>><br /> > > >>>><br /> > > >>>><br /> > > >>>><br /> > > >>> I've not experienced this with using any DOM functions, but if we<br /> > > >>> can<br /> > > >>> see your code it might help us.<br /> > > >>><br /> > > >>> Thanks,<br /> > > >>> Ash<br /> > > >>> http://www.ashleysheridan.co.uk<br /> > > >>><br /> > > >>><br /> > > >>><br /> > > >>><br /> > > >>> -- <br /> > > >>> PHP General Mailing List (http://www.php.net/)<br /> > > >>> To unsubscribe, visit: http://www.php.net/unsub.php<br /> > > >>><br /> > > >><br /> > > >><br /> > > >><br /> > > >><br /> > > >> Well i'll pop the PHP down here, i'll trim it as much as i can:<br /> > > >><br /> ____________________________________________________________ ____________<br /> > > >><br /> > > >> $code = $_POST['code'];<br /> > > >> $name = $_POST['name'];<br /> > > >> $desc = $_POST['desc'];<br /> > > >> $size = $_POST['size'];<br /> > > >> $price = $_POST['price'];<br /> > > >><br /> > > >><br /> > > >> #load an XML document into the DOM<br /> > > >><br /> > > >> $dom = new DomDocument();<br /> > > >> $dom -> load("items.xml");<br /> > > >><br /> > > >> #create elements<br /> > > >><br /> > > >> $Xitem = $dom -> createElement("item");<br /> > > >> $Xcode = $dom -> createElement("code");<br /> > > >> $Ximage = $dom -> createElement("image");<br /> > > >> $Xname = $dom -> createElement("name");<br /> > > >> $Xdesc = $dom -> createElement("desc");<br /> > > >> $Xsize = $dom -> createElement("size");<br /> > > >> $Xprice = $dom -> createElement("price");<br /> > > >><br /> > > >> #create text nodes<br /> > > >><br /> > > >> $Xcodetext = $dom -> createTextNode($code);<br /> > > >> $Ximagetext = $dom -> createTextNode( "<![CDATA[<img src=\"uploads/<br /> > > >> $UploadName\" alt=\"Homepage Image\" width=\"124\" height=\"70\"<br /> > > >> border=\"1\" onclick=\"MM_openBrWindow('uploads/<br /> > > >> $UploadName','Preview','width=680,height=520')\" />]]>" );<br /> > > >> $Xnametext = $dom -> createTextNode($name);<br /> > > >> $Xdesctext = $dom -> createTextNode($desc);<br /> > > >> $Xsizetext = $dom -> createTextNode($size);<br /> > > >> $Xpricetext = $dom -> createTextNode($price);<br /> > > >><br /> > > >> #append the text nodes to the inner nested elements<br /> > > >><br /> > > >> $Xcode -> appendChild($Xcodetext);<br /> > > >> $Ximage -> appendChild($Ximagetext);<br /> > > >> $Xname -> appendChild($Xnametext);<br /> > > >> $Xdesc -> appendChild($Xdesctext);<br /> > > >> $Xsize -> appendChild($Xsizetext);<br /> > > >> $Xprice -> appendChild($Xpricetext);<br /> > > >><br /> > > >> #append the inner nested elements to the <item> element<br /> > > >><br /> > > >> $Xitem -> appendChild($Xcode);<br /> > > >> $Xitem -> appendChild($Ximage);<br /> > > >> $Xitem -> appendChild($Xname);<br /> > > >> $Xitem -> appendChild($Xdesc);<br /> > > >> $Xitem -> appendChild($Xsize);<br /> > > >> $Xitem -> appendChild($Xprice);<br /> > > >> $Xitem -> setAttribute("Code",$code);<br /> > > >><br /> > > >> #append the <title> element to the root element<br /> > > >><br /> > > >> $dom -> documentElement -> appendChild($Xitem);<br /> > > >><br /> > > >> #create a new enlarged xml document<br /> > > >><br /> > > >> $dom -> save("items.xml");<br /> > > >><br /> > > >> _____________________________________________________<br /> > > > It looks like it's because you are creating an image object by<br /> > > > appending<br /> > > > a text node inside CDATA to it. My guess is that a text node will have<br /> > > > the contents automatically made 'safe' for the XML entities which<br /> > > > are <,<br /> > > >> , &, etc.<br /> > > ><br /> > > > Why are you appending the child item like this? What's wrong with<br /> > > > adding<br /> > > > it as a proper object, attributes and all?<br /> > > ><br /> > > > Thanks,<br /> > > > Ash<br /> > > > http://www.ashleysheridan.co.uk<br /> > > ><br /> > > ><br /> > > ><br /> > ><br /> > ><br /> > > Hi Ash,<br /> > ><br /> > > Thanks for getting back to me,<br /> > > In all honesty this method is what's implemented in the course book<br /> > > i've been following.<br /> > ><br /> > > I been using XML longer and i've never had this issue using image tags<br /> > > before and getting the output I expected.<br /> > > Is there a way around this safety mechanism ? Otherwise i'll have to<br /> > > think of another way of doing this.<br /> > ><br /> > > Cheers.<br /> > ><br /> ><br /> > Just create the image tag using the same methods as you're creating the<br /> > other nodes. So the image object would contain several attribute nodes,<br /> > but would have no regular child nodes of its own.<br /> ><br /> > Thanks,<br /> > Ash<br /> > http://www.ashleysheridan.co.uk<br /> ><br /> ><br /> ><br /> <br /> <br /> <br /> <br /> -- <br /> PHP General Mailing List (http://www.php.net/)<br /> To unsubscribe, visit: http://www.php.net/unsub.php</p> </article> <footer> <a href="/">Index</a> | <a href="/impressum.php">Impressum</a> | <a href="/datenschutz.php">Datenschutz</a> | <a href="https://www.xodox.de/">XODOX</a> </footer> </main> </body> </html>