Juanvulcano Juanvulcano - 3 months ago 10
PHP Question

Display only certain elements XML File

I have a php script that retrieves an XML file from a database and displays it in html.

I only want to display some parameters from the XML in my html, I was wondering what was the best way to do it.

Suppose that bellow I would only like to display the Format and TIM attributes of the XML. What would I need to modify on the html?
I've read that I can delete elements using XSLT but then I would need to modify the xml in the database, is there another way to do it with just html or xml?

Xml

<?xml version="1.0" encoding="UTF-8"?>
<File>
<track type="General">
<Format>MPEG-4</Format>
<Codec_ID>mp42</Codec_ID>
<Codec_ID>mp42 (mp42/mp41)</Codec_ID>
<Tagged_date>UTC 2016-03-28 20:21:33</Tagged_date>
<TIM>00:00:00:00</TIM>
<TSC>60000</TSC>
<TSZ>1001</TSZ>
</track>
</File>


Html

<span class="meta-label"> <?php echo $database['XML'] ?> </span> <span class="meta-content">Content</span></li>

Answer

To answer to your question: No. Not possible with "just HTML or XML".

However I feel like simply answering your question does not really help you. Thus, here is a way you could handle this in PHP (since your question is tagged with the PHP tag as well): You could use the SimpleXMLElement class, to which constructor you can pass your XML, and then access is pretty simply, like so:

<?php
// caution, no valid XML in example!
$xmlElement = new SimpleXMLElement('<your><xml><here>'); 
echo $xmlElement->track[0]->Format
Comments