Jump to content

PHP and XML


radox

Recommended Posts

While I appreciate your reply, I'm looking for a response from someone that has implemented XML posting through web services like XML_RPC. I need an example file or code to get started....

This is becoming common practice for automation between servers.

The company has given me and XML example file and the associated XSD file.

It's up to me to create the file on my end to intercept their transmission.
Link to comment
https://forums.phpfreaks.com/topic/8822-php-and-xml/#findComment-32386
Share on other sites

Does this example help any? (PHP5 required)

:::newsfeed.xml:::
[code]<?xml version="1.0" encoding="utf-8"?><!-- generator="whocares" -->
<rss version="0.92">
<channel>
<title>Website Name</title>
<link>http://www.websiteurl.com</link>
<description>Description of website</description>
<lastbuilddate>Sun, 19 Sep 2004 04:34:52 +0000</lastbuilddate>
<docs>http://backend.userland.com/rss092</docs>

<item>
  <title>1st Title</title>
  <description>1st Description</description>
  <link>http://www.websiteurl.com/1stlink/</link>
  <pos>L</pos>
</item>

<item>
  <title>2nd Title</title>
  <description>2nd Description</description>
  <link>http://www.websiteurl.com/2ndlink/</link>
  <pos>R</pos>
</item>
</channel>
</rss>[/code]

:::newsfeed.xsl:::
[code]<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <xsl:apply-templates/>
</xsl:template>


<xsl:template match="rss/channel">
     <DIV class='main'>
           <h3><xsl:value-of select="title"/></h3>
           <p><xsl:value-of select="description"/></p>
           <xsl:apply-templates  select="item"/>
     </DIV>
</xsl:template>

<xsl:template match="item">
             <DIV class='item'>
                  <table border='1' width='100%'>
                   <xsl:choose>
                        <xsl:when test="pos='L'">                  
                          <tr>
                            <td><xsl:apply-templates select="title"/></td>
                            <td><xsl:apply-templates select="description"/></td>
                          </tr>
                        </xsl:when>
                        <xsl:otherwise>                    
                          <tr>
                            <td><xsl:apply-templates select="description" /></td>
                            <td><xsl:apply-templates select="title" /></td>
                          </tr>
                        </xsl:otherwise>
                   </xsl:choose>
                  </table>
             </DIV>

</xsl:template>

<xsl:template match="title">
    <span style="color: #0000FF"><xsl:value-of select="." /></span>
</xsl:template>

<xsl:template match="description">
    <span style="color: #FF0000"><xsl:value-of select="." /></span>
</xsl:template>
</xsl:stylesheet>[/code]

:::newsfeed.php:::
[code]<html>
<head>
<meta name="generator" content="PhpED Version 4.5 (Build 4513)">
<title>XSLT sample</title>
<link rel="shortcut icon"  href="favicon.ico">
<STYLE>
DIV.main {border: 1pt solid gray; background-color: silver; width: 400px; padding: 10px}
DIV.item {border: 1pt solid gray; background-color: #FFFFC0; width: 380px; margin-bottom='5'}
</STYLE>
</head>
<body>
    <?php
    $xml = simplexml_load_file('newsfeed.xml');
    $xsl = simpleXML_load_file('newsfeed.xsl');
    $proc = new XsltProcessor();
    $proc->importStylesheet($xsl);
    $newxml = $proc->transformToDoc($xml);
    print $newxml->saveXML();
    ?>
</body>
</html>[/code]
Link to comment
https://forums.phpfreaks.com/topic/8822-php-and-xml/#findComment-32812
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.