0

I need some help with my PHP, I'm generating to make the xml output.

On the xml tree, I can see that I'm using double quotes but i want to use the single quotes.

I want to add the single quotes in the

<programme 
    channel='MY CHANNEL NAME' 
    start='20140504113000' 
    stop='20140504131000'>

On the xml tree, it will show like this:

<programme 
    channel="MY CHANNEL NAME" 
    start="20140504113000" 
    stop="20140504131000">

You will see like this:

Screenshot

When I open the source code, I can see that I have got the single quotes.

<programme 
    channel='MY CHANNEL NAME' 
    start='2014-05-04' 
    stop='2014-05-05'>
</programme>

Not sure if the problem is lie in this line:

$xml .= "<programme channel='$my_id $channel' start='$stoptime' stop='$starttime'>";

Here is the code:

    <?php
    header("Content-Type: text/xml");
    $my_id = '101';
    $channel = 'ABC FAMILY';
    $starttime = '2014-05-04';
    $stoptime = '2014-05-05';

    $xml .= "
      <programme channel='" . $my_id. " " . $channel . "' start='" . 
$starttime . "' stop='" . $stoptime . "'>";

    //$xml .= "<programme channel='".$channel."' start='".$starttime."'>";
    //$xml .= "<programme channel='$my_id $channel' start='$starttime' 
stop='$stoptime'>";

    $xml .= '</programme>';

    echo $xml;
    $handle = fopen("myChannel.xml", "w"); 
    fwrite ($handle, $xml);
    ?>

How I can see the single quotes in the xml tree when I'm generating to make the xml?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109

2 Answers2

2

I think the XML tree doesn't show the exact source, but just a rendering of the data. The XML is loaded into memory and then it is displayed using indenting, 'normalized' quotes and highlighting, so you can read it more easily. The string values are displayed in double quotes, so there you go.

As you say, the source has single quotes, so everything is outputted as expected. It's just the way it's displayed. No worries.

GolezTrol
  • 114,394
  • 18
  • 182
  • 210
  • Thank you for clarify this, are there any way if it possible to output the rendering data in the xml where i can see the single quotes instead of double quotes? –  May 04 '14 at 20:15
  • You can add style to XML: http://www.w3.org/Style/styling-XML But I don't know/don't think you can choose the quotes for rendering (not sure, I don't have much experience in styling XML). XML is not for reading in the first place. It contains data that can be used or transformed to other data. The XML document is not the end product. It's about the stuff between the quotes. – GolezTrol May 04 '14 at 20:20
  • Related topic: http://stackoverflow.com/questions/6800467/quotes-in-xml-single-or-double – Naeel Maqsudov May 04 '14 at 20:21
  • @NaeelMaqsudov thank you for posting the link, but i cannot find the code that I'm looking for which related to my code. can you please post the code that what i exactly want? –  May 04 '14 at 20:29
  • That link doesn't contain relevant code. It's about the fact that semantically there's no difference between single or double quotes. I guess @NaeelMaqsudov, like me, doesn't understand why this is a problem to you. :) – GolezTrol May 04 '14 at 20:30
  • well I don't want to print the double quotes to the xml tree because I'm making the xml tv guide and I need single quotes so it would be much easier for me to parsing the strings from the xml tree. Hope you get my point why I need the single quotes? :) –  May 04 '14 at 20:44
  • 1
    The whole point of XML is that you should be able to read it if it is valid XML with the right structure, so your parser should understand double quotes as well. But why would you parse from the XML tree? You've got the source of the XML file at hand. Besides, there ar numerous parsers available. You shouldn't worry about that at all. – GolezTrol May 04 '14 at 20:46
  • See for instance: http://www.php.net/manual/en/book.xml.php There are XML writers too, so you don't have to write it yourself. Sure makes working with special characters a lot easier. – GolezTrol May 04 '14 at 20:49
  • @DanielEzekiel, Shoing double quotes depends on browser. Most browsers doing this way. I hope it is possible to use XSLT to make viewable single quotes (It will take time to create DTD and XSLT example (DTD will be also required)). But in this case result will look different as well. It would not show expand/collapse buttons… By the way, what kind of parsing you are doing thurther? You document contains single quotes. I don't understand how browser rendering may affect to parsing? – Naeel Maqsudov May 04 '14 at 20:58
0

This XML independently from quotes always produces single quotes

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xml" href="#stylesheet"?>
<!DOCTYPE programs [
<!ATTLIST xsl:stylesheet
  id    ID  #REQUIRED>
]>
<programs>
<xsl:stylesheet id="stylesheet" version="1.0"       xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
  <html>
  <body>
  <h2>PROGRAMS</h2>
    <table >
      <tr bgcolor="#9acd32">
        <th/>
        <th/>
        <th>ch</th>
        <th>strt</th>
    <th>stop</th>
    <th/>
  </tr>
  <tr>
    <td>&lt;programs&gt;</td>
  </tr>
  <xsl:for-each select="programs/programme">
  <tr>
    <td/>
    <td>&lt;programme&gt;</td>
    <td>channel='<xsl:value-of select="@channel"/>'</td>
    <td>start='<xsl:value-of select="@start"/>'</td>
    <td>stop='<xsl:value-of select="@stop"/>'</td>
    <td>&lt;/programme&gt;</td>
  </tr>
  </xsl:for-each>
  <tr>
    <td>&lt;/programs&gt;</td>
  </tr>
</table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
<programme channel='MY CHANNEL NAME' start="20140504113000"  stop='20140504131000'/>
<programme channel="MY CHANNEL NAME2" start='20140504113000'  stop="20140504131000"/>
</programs>

After this example probable you will want to do all your parsing with XSLT ;)

Naeel Maqsudov
  • 1,352
  • 14
  • 23