Jump to content

PHP and XML


radox

Recommended Posts

I could use a little insight on XML posting.

I have a company that would like to "post" XML data to one of my servers.
I really don't understand this "posting" process.

Does anyone have an example file, or snippet of code, they can send to help me understand?

Much appreciated.
Link to comment
Share on other sites

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
Share on other sites

Yes, something like that...but the raw data passes over secure http, not ftp.

I just can't seem to find an example file or code.

I guess there is a PHP function called "get_xml_raw" or something along those lines??

I'm looking for any direction really.

Thanks for your post.
Link to comment
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.