|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Parsing an XML to php
i was look at a xml file which is
click here to view the xml file can anyone tell me how can i Parse it so that AvgTimeInAge2="309" turn into a time form for example (mins:sec). I try doing it but it turn out to be 309 instead of mins:sec thanks Last edited by blance : April 2nd, 2004 at 08:37 PM. |
|
#2
|
||||
|
||||
|
The XML parser cannot do any mathematical functions, like divide 309 by 60. It only provides an interface so that you can access the XML data as nodes. You will need to obtain the 309 and then divide by 60 in your PHP code, the XML nor the parser can do that on their own.
|
|
#3
|
|||
|
|||
|
Here is an example of one way of doing it if you are
using a stylesheet: Code:
<?xml version="1.0"?>
<time>
<seconds>309</seconds>
</time>
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<xsl:apply-templates select="/time/seconds"/>
</xsl:template>
<xsl:template match="/time/seconds">
<xsl:value-of select="floor(. div 60)"/>:<xsl:value-of select=". mod 60"/>
</xsl:template>
</xsl:stylesheet>
You can also use the EXSLT extension functions (www.exslt.org) |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Parsing an XML to php |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|