Solved

How to add XML to a Web Page

Posted on 2012-03-15
13
262 Views
Last Modified: 2012-06-27
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
Comment
Question by:bleggee
  • 5
  • 3
  • 3
  • +1
13 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 37727694
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
 
LVL 1

Author Comment

by:bleggee
ID: 37727728
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
 
LVL 7

Expert Comment

by:micropc1
ID: 37727774
.
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 500 total points
ID: 37728186
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37728193
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
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37728203
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37728224
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
 
LVL 1

Author Comment

by:bleggee
ID: 37733683
THANKS GERTONE !!
0
 
LVL 7

Expert Comment

by:micropc1
ID: 37733716
Um..thanks. I guess my period did the trick eh? :)
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 37734273
Welcome, but uhm, did you not accept the wrong answer? :-)
0
 
LVL 1

Author Comment

by:bleggee
ID: 37735112
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
 
LVL 7

Expert Comment

by:micropc1
ID: 37735124
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now