Jump to content


Photo

PHP and XML


  • Please log in to reply
8 replies to this topic

#1 radox

radox
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 01 May 2006 - 04:50 PM

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.

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 01 May 2006 - 05:01 PM

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.

Info: PHP Manual


#3 radox

radox
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 01 May 2006 - 05:16 PM

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.

#4 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 01 May 2006 - 05:35 PM

Alright... you don't need to get snippy. You could have explained yourself a little better.

Info: PHP Manual


#5 radox

radox
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 01 May 2006 - 06:49 PM

I didn't mean to be snippy...sorry...

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

#6 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 01 May 2006 - 07:32 PM

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.

Info: PHP Manual


#7 phporcaffeine

phporcaffeine
  • Members
  • PipPipPip
  • Advanced Member
  • 361 posts
  • LocationOhio, USA

Posted 02 May 2006 - 10:59 PM

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?
Thanks,

Ryan Huff
President & Founder, MyCodeTree
support@mycodetree.com | http://mycodetree.com

#8 radox

radox
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 02 May 2006 - 11:24 PM

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.

#9 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,015 posts

Posted 02 May 2006 - 11:45 PM

Does this example help any? (PHP5 required)

:::newsfeed.xml:::
<?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>

:::newsfeed.xsl:::
<?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>

:::newsfeed.php:::
<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>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users