• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

How to add XML to a Web Page

Hi - I was looking for a tutorial or a "How To" in order to learn how add 1 small XML call to a web page of ours. It is 2-lines of  XML code (our Key and a part number) and the XML returned is simply a "Quantity in Stock" that we want to display on our web page)
Although we are XML Dummies, we have done PHP coding with MySQL, Web development, have done Web Reply Forms, etc. and do command-level Linux. So we are thinking "How hard could XML be?"  If it matters, we are doing this on Linux/LAMP Servers, NOT Microsoft/IIS.

Before we start digging around Googling & Reading books, I thought someone might point us in the right direction ...

Thanks all !
- B
0
bleggee
Asked:
bleggee
  • 5
  • 3
  • 3
  • +1
1 Solution
 
käµfm³d 👽Commented:
XML is not executable code--it is markup language. When you say "add 1 small XML call" do you mean that you want to call a web service?
0
 
bleggeeAuthor Commented:
Hi Kaufmed - Specifically, I want to get a part's current "Quantity in Stock" printed on my web page ... per my Vendors XML, which looks like this:
===============================================================
*** REST Quantity Check ***
To use the REST option, you will need to access the ‘quantitycheck script by sending XML to
https://www.eldoradopartner.com/quantitycheck/

The XML sent will need to use the POST method via port 443 (the default port for https). The
product, the product identifier (‘products_model’) and the stock needed should be provided in an XML block like this:
<item></item>
For example, to find out if there is enough stock to order 3 units of a product with the
‘products_model’ 1234AB, and your store key is 1a2aa3456aaaa789a0a123456a7a890a, you
would need to send the following XML:

<key>1a2aa3456aaaa789a0a123456a7a890a</key>
<item>123AB</item>
To the following url https://eldoradopartner.com/quantitycheck/

The following XML will be returned:

<quantity>
<item>123AB</item>
<amount>41</amount>
</quantity>

If the item is out of stock, a quantity of 0 will be returned:

<quantity>
<item>123AB</item>
<amount>0</amount>
</quantity>

*** SOAP Quantity Check ***
If you are familiar with SOAP and would like to use this protocol to check quantity, simply go to
the following url:
https://www.eldoradopartner.com/quantitycheck/wsQuantityCheck.php
Click on WSDL link to view WSDL (web service description) for the service.
===============================================================
0
 
micropc1Commented:
.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Geert BormansCommented:
Hi

What you want to do is access a web service from your page.
So there is two layers of functionality you have to develop
1. Access the webservice
2. Access the XML returned by the webservice

1. The webservice offers you two options to get the data
A. SOAP
B. REST

1.A. SOAP is a complex beast. Simply too much for a task like this. It accepts requests hidden in a SOAP envelope It returns responses, hidden in a different SOAP envelope. It is a bit like sending lettres. The outside is uniform: an envelope, an address and a stamp. But you need to unpack it in order to read. For that you either need to hack the XML based SOAP envelope, or use a SOAP library. I don't recommend that you use it in this project (but PHP has a pretty goed soap library

1.B. REST. is similar to SOAP but a lot simpler. You basically send a request (preferably http GET) and you get a representation of the data back. The representation often (as in this case) is an XML document. Go for this approach here

The service (I just checked) seems to require a http POST. This means that you need a http client in your code that can do a  http POST request. Now you have to make a decision. Do you process this client side or server side. You can do both. Given that you need to do a http POST and you need to take different browsers into account, I would go for server side. You can do JavaScript httpPost, no problem. PHP on the server seems more elegant to me.

2. Once the XML is returned to you. There are a zillion ways of getting to the actual value. Since we have just decided that you are going to do a server side PHP for this: there is XSLT for complex transforms (you don't need it here) There is XPath access to a DomDocument. And there is simpleXML. Have a look at the latter. It will serve your purpose well.

There is a hybrid approach you might like. Use the httpPost from the PHP server side and post the XML (as a data island or alongside ) the HTML. And process the XML in the HTML page client side. Again, you will hit some cross browser issues. The XML is too simple and too small to gain a benefit from that approach
0
 
Geert BormansCommented:
here is a link to the simpleXML link
(note that you need to explicitely enable it for older PHP)
http://www.php.net/manual/en/simplexml.examples-basic.php
0
 
Geert BormansCommented:
for getting access to the REST service, you can use the http client library
http://www.php.net/manual/en/book.http.php
but you need to explicitely add it to your install
0
 
Geert BormansCommented:
and you are right... as the simpleXML samples tell you: "how hard can XML be?"
the XML is the easy part in this project.
Pulling it off the REST service is the hard(er) coding part
0
 
bleggeeAuthor Commented:
THANKS GERTONE !!
0
 
micropc1Commented:
Um..thanks. I guess my period did the trick eh? :)
0
 
Geert BormansCommented:
Welcome, but uhm, did you not accept the wrong answer? :-)
0
 
bleggeeAuthor Commented:
Moderator ... let me take a stab at awarding points again ... thx everyone for being on top if this.
MicroPC1 - Yes, that "period" was impressive, I tried & tried using it, but I think I'll have to go with one of the other answers this time :-)
0
 
micropc1Commented:
Yeah np,  i actually did post something substantial at first, but after reading your post again I decided to remove it. Unfortunately there's no way to delete a post (as far as I can tell), so I just stuck a period in there.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 5
  • 3
  • 3
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now