Solved

Whats on the server-side of an XML FEED?

Posted on 2014-04-21
10
227 Views
Last Modified: 2014-05-08
Hi all - I want to have an XML Feed for data that I have, so that I can "supply" data to others. Now I am stumped. Is there "XML Feed Server" software?
0
Comment
Question by:bleggee
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
10 Comments
 
LVL 52

Expert Comment

by:Scott Fell, EE MVE
ID: 40013836
You would use your serverside scripting such as PHP to generate the feed.
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40014629
...data that I have...
The data you have is the key to success here.  Is it in an existing hierarchy or in a data base?  If you want to show us some examples, we can show you how to get the data from its current form into an XML document.

XML is hierarchical.  XML is string data.  There are no other data types in an XML document.  Data elements are easiest to access if you use plain-text tag names.  Avoid blanks, dashes and special characters; the underscore is a good substitute for a blank.  XML requires matched open-tags and close tags like this:

<name>Ray</name>

You can create an XML document using string concatenation in PHP.  The PHP HEREDOC notation is very easy to use for XML fragments.  The fragments can be assembled into complete XML hierarchies using a cascade of HEREDOC or string concatenation.  When you show us a little data, I will be glad to show you how to create the XML documents with a few lines of PHP code.

You might consider using JSON instead of XML.  It is more compact since it has no need for closing tags, and it plays well with any server or client programming language including JavaScript.  JSON is always in UTF-8 character encoding.  The JSON standard is documented here:
http://json.org/
0
 
LVL 1

Author Comment

by:bleggee
ID: 40015755
Thanks Ray. I had been wondering if JSON was a good choice also!

The data right now is in Excel, so we would export, reformat, etc. as needed.  I attached a small sample of the data here, same file, as an XLSX and a CSV
Sample-Product-File-for-Ray.csv
Sample-Product-File-for-Ray.xlsx
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40015800
Based on the column headers, a reasonable hierarchy might look something like this.
Product Class
|
|__SubClass
   |
   |__3rd Class
      |
      |__Item
         |
         |__Item No.
         |
         |__Item Description
         |
         |__Length
         |
         |__Width 1
         |
         |__Height 1
         |
         |__BRAND
         |
         |__Description

Open in new window

PHP has good functions for manipulating CSV files.
http://php.net/manual/en/function.fgetcsv.php
0
 
LVL 1

Author Comment

by:bleggee
ID: 40016303
Great! So 1 last question ... I write some PHP code, produce an XML file (I presume a flat text file).  Then how does someone access it? Do I just leave the flat XML file on a web server, and then give someone the URL, filename, & XML Field Format?
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40016312
just leave the flat XML file on a web server, and then give someone the URL, filename, & XML Field Format?
That's almost exactly it.  An XML document is a flat-text file.  The file can be formatted for readability since whitespace and newline characters outside of the tags have no meaning to XML, so you can put in line breaks and indentation. I would name the XML file something like XXX.xml, give them the fully qualified URL like http://example.com/XXX.xml and any documentation you might need to provide that describes the contents of the fields.

When you want to consume an XML document in PHP you can use SimpleXML_Load_File() or similar to create an object.  PHP iterators like foreach() can access the properties of the object.  The only "gotcha" I've found when using SimpleXMLElement objects shows up when you try to put the object into the PHP session.  Don't do that, or if you're curious, try it to see how it fails :-)
0
 
LVL 1

Author Comment

by:bleggee
ID: 40016317
So I presume that the Hierarchy of the Data is mostly for Human readability?
0
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 40016339
Not exactly -- it's both for human interest and for software to access the data in the XML document.  I'll make you an example.  Back in a few moments.
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 40016359
Please see http://iconoun.com/demo/temp_bleggee.php

Data organization and data readability go hand-in-hand here.  You could write the XML string all on one line with no indentation or line breaks and it would still work programmatically but it would be harder to read.

<?php // demo/temp_bleggee.php
error_reporting(E_ALL);
echo '<pre>';

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/XML/Q_28417154.html

// AN XML DOCUMENT DEFINED WITH PHP "HEREDOC" NOTATION
$xml = <<<EOD
<?xml version="1.0" encoding="UTF-8"?>
<info>
  <people>
    <person>
      <name>
        <first>Brian</first>
        <last>Leggee</last>
      </name>
      <url>leggee.com</url>
    </person>
    <person>
      <name>
        <first>Ray</first>
        <last>Paseur</last>
      </name>
      <url>iconoun.com</url>
    </person>
  </people>
</info>
EOD;

// SHOW THE XML WITH TAG FORMATTING
echo PHP_EOL . htmlentities($xml);
echo PHP_EOL;

// MAKE AN OBJECT AND SHOW IT
$obj = SimpleXML_Load_String($xml);
var_dump($obj);
echo PHP_EOL;

// USE ITERATORS TO ACCESS SOME PARTS OF THE OBJECT
foreach ($obj->people->person as $person)
{
    echo PHP_EOL . $person->name->first;
    echo ' ';
    echo $person->url;
}

Open in new window

0
 
LVL 1

Author Comment

by:bleggee
ID: 40016366
Thank you very much Ray !!    Appreciate it.

- Brian
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
restriction of entering a a page 5 34
syntax error, unexpected '?' in phpunit 5 28
How do I remove "" from json_encode 5 22
exchange, squid, proxy, linux 6 40
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question