Jump to content

Archived

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

radox

PHP and XML

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.

Share this post


Link to post
Share on other sites
Maybe you should ask them what they mean first. If they just want to store XML files on your server, that's nothing more than a normal upload script.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Alright... you don't need to get snippy. You could have explained yourself a little better.

Share this post


Link to post
Share on other sites
I didn't mean to be snippy...sorry...

Did my last post help? Do you have any sort of resolution or example?

Share this post


Link to post
Share on other sites
That will probably help someone, but I don't personally have any experience in that area. But I'll bump the thread again for you just in case someone else does.

Share this post


Link to post
Share on other sites
Your talking about something like an EDI transmission yes? They FTP the file, your script reads and then acts upon that data like "posting" it to other databases and applications?

Share this post


Link to post
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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites

×

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.