bleggee
asked on
Whats on the server-side of an XML FEED?
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?
You would use your serverside scripting such as PHP to generate the feed.
...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/
ASKER
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
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
Based on the column headers, a reasonable hierarchy might look something like this.
http://php.net/manual/en/function.fgetcsv.php
Product Class
|
|__SubClass
|
|__3rd Class
|
|__Item
|
|__Item No.
|
|__Item Description
|
|__Length
|
|__Width 1
|
|__Height 1
|
|__BRAND
|
|__Description
PHP has good functions for manipulating CSV files.http://php.net/manual/en/function.fgetcsv.php
ASKER
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?
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 :-)
ASKER
So I presume that the Hierarchy of the Data is mostly for Human readability?
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much Ray !! Appreciate it.
- Brian
- Brian