Link to home
Start Free TrialLog in
Avatar of kenfcamp
kenfcampFlag for United States of America

asked on

data exchange via http

I'm new to XML, so please excuse me if this question doesn't make much sense.

I've got php scripts that generate xml - they work fine

I've got a html and xml pages that pull xml tags from the php scripts displaying the results - they work fine

but when I place the html or xml page outside my network they're dead even when I replace the 'src' path to reflect the complete http address of the php scripts.

I know I more than likely am missing something to transfer data requests via http but I don't know what (as I said I'm new to this)

In short , heeeeeeeelp ;-)
Avatar of Shalom Carmel
Shalom Carmel
Flag of Israel image

kenfcamp,
Do you create the XML and HTML files offline and then upload them to a web server, or does the PHP script work for each request?

What does the URL of the resulting XML files look like?

ShalomC
Post a URL which doesn't work.

Post a page which cannot be accessed.
Avatar of kenfcamp

ASKER

shalomc:

PHP works with each request

:sample php result:

 <?xml version="1.0" ?>
- <dataset>
- <row>
  <name>john doe</name>
  </row>
  </dataset>

:sample.html:

<html>
<body>
<xml id="name" src="http://somesite.com/test1.php?id_gen=0001"></xml>

<table border="1" datasrc="#name">

<tr>
<td><span datafld="name"></span></td>
</tr>

</table>


*id_gen would be produced by filling in a form, but is provided in the link for testing purposes. The number is searched against mysql through php to obtain the name associated with the number.

The URL with in 'src' is an example of what I've tried.
Sounds almost like a cross domain data access security issue.  Are the XML and the PHP page both located at:  http://somesite.com/ ??

There's no issue with data access over http, as everything's text.  Nothing in particular to do there.  But if the HTML page is at http://foo.com  and the XML is coming from http://bar.com, you'll have problems.  At the least, a dialog informing the user that this page is trying to access data outside of it's control.  At the worst, it just won't work, and no error to tell you why.

Aggregating web services pretty much has to be done on the server, where these issues don't arise.

Regards,
Mike Sharp
rdcpro;

< But if the HTML page is at http://foo.com  and the XML is coming from http://bar.com, < you'll have problems


That's exactly what I'm trying to do, and that's what I'm having 'problems' lol.

Any suggestions?

exchange of data is supposed to be possible (easy from what I've been reading about it) but I can't for the life of me, get enough clear "beginner" information on what's needed, how it works etc
Well, the only real solution I know of is to do this aggregation on the server...It's a browser security issue.

You have a page on the server that, when requested, gets the data from the source and streams it back to the client.  Sort of how a RSS newsfeed works.

Regards,
Mike Sharp
hmmm any suggestions on where a beginner would (should) start?
I'm not real familiar with PHP, but essentially you need a page on your server (the one that serves the HTML page) to load the XML, and send it to the client.  That way the client sees only requests/responses from the same domain.

Do both sites use PHP, and do you have access to both (ie: is the data coming from a page you wrote/can modify)?
rdcpro:

######defination##################################
$serverA - site with php generating xml

$serverB - remote site that will access the php/xml results
##############################################

$serverA is running php, and I have full access to it

$serverB will be remote with no access to it nor does it have php.

however for testing purposes I'm using a secondary server to represent $serverB which also has 'no' php capabilities, but I do have full access for testing and modification.

< essentially you need a page on your server (the one that serves the HTML page) to < load the XML, and send it to the client.  That way the client sees only
< requests/responses from the same domain.

I had tried that *see first reply and it works fine when on $serverA, but is dead when moved to $serverB

I've checked all logs for bother servers, and no errors are reported.

I know I'm not doing something right.. but can't figure out what.

I've even created a static xml page with sample data and that doesn't even work

I just don't get it.

You have to get the XML data into your XML island, but cross domain issues stop your application from working.

I would try to use XMLHTTP on the client side, so the HTML page loaded from serverB will retrieve the XML data from serverA via JavaScript.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmobjxmlhttprequest.asp

XMLHTTP can be used both by client Javascript AND by ASP server.

A sample usage:

function RetrieveRemoteXML() {
       var URL = "http://somesite.com/test1.php?id_gen=0001" ;
    var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    xmlhttp.Open('GET', URL, false);
    xmlhttp.Send();
    return xmlhttp.responseXml;
}

ShalomC
ShalomC:

will this work on a *nix server?

Part of the problem is that all documentation that is even close to what I'm trying to do are using the assumption that the server is M$ and or utilizing ASP pages.
Client-side XMLHTTP will have the same cross-domain issues, because it uses the browser's security settings.  Also that ProgID is for MSXML 2.0, and if the XML HTTPRequest object is going to be used, one should probably use MSXML 3's object.

But, to answer kenfcamp, the client side control won't care at all what the remote server is (as long as its on the same domain).  The server should set the contentType to "text/xml" .


But this won't help you.


I take it Server B is the one that's serving the HTML page to the browser?

If so, then Server B must access Server A, get the XML, then serve it to the client that it served the HTML page to.

Here's how it maps out:
Server A
    page: datasource.xml (XML Data Source)

Server B
    page 1:  myPage.html (HTML Page with DataIslands or XMLHttpRequestObject that reference myData.xml)
    page 2:  myData.xml  (server-side page that loads datasource.xml from server B, sets the ContentType header to "text/xml" and serves the XML to the requesting client)


Follow?

This is exactly how a RSS news feed works.  If I have a website that subscribes to a syndicated XML news feed, I must get the data using my server, transform it into HTML (or leave it as XML) and then serve it to my clients (the ones that are hitting my site).  In any page that I send to my site visitors, I can't just direct a data island to a remote source, for security reasons.


Now in our scenario, Server B can use whatever technology it wants to get Server A's XML feed.  And Server A can use whatever it wants to generate the XML...But the client can only get data from the same domain as the page it's visiting.  However, the client doesn't care how the data is generated (ie: whatever platform you want to use will do just fine).

Regards,
Mike Sharp

rdcpro

Thanks for the explanation.

Do you know of any easy to follow (beginner) tutorials on how to achieve this?
(I have been trying and I'm still researching this. but am getting nowhere fast)

Or if you could provide an example based on the sample provided in my first comment that I can try and test against I'd appreciate it.

I hope I'm not coming across as a dimwit: -\
Nah, none of it's obvious until you beat your head against the wall for while!

Here's how I did one RSS feed on a page.  I know this is Microsoft ASP, but it might show you what's going on.  The user visits a web page on my server.  The Web page goes to another server (on a different domain) to obtain the XML.  In my case, I wanted to cache the XML locally on the filesystem, and only refresh it every few minutes.  What makes it work is the:

       xmlDoc.setProperty "ServerHTTPRequest", true

In the MS world, this causes the xmlDOMDocument object to use HTTP to get the file.  Various platforms have similar mechanisms for this.  

In any case, this is how it works.

1. The web page checks to see how old the cached file is (using the filesystem object)
2. If it needs a fresh copy, it gets the XML, using the xmlDoc object's load method (after setting ServerHTTPRequest to true.
3. It renders the XML using XSLT, and sends the result to the client.

In your case, the code below won't do the rendering, it will simply send the XML to the client.  But the code has to be on the same domain as the web page that contains the data island.


This is the important part.  Whatever server that has the HTML page, must also have a page that works server-side, in whatever platform the server uses, to call on your XML datasource page.  It gets the XML over HTTP from your datasource.

So, the HTML page is served from http://somesite.com/myPage.html, and looks like:

<html>
<body>
<xml id="name" src="http://somesite.com/myXMLprocessor.foo"></xml>
<table border="1" datasrc="#name">
<tr>
<td><span datafld="name"></span></td>
</tr>
</table>

When the client HTML page loads, the data island goes back to the same server, and requests myXMLProcessor.foo (it could be any server-side processing language).

myXMLProcessor.foo will go to your datasource, on whatever domain it is, get the XML and return it to the data island.

Microsoft ASP code sample below.

Regards,
Mike Sharp



<%
' DIM Variables for Command processing
Dim xmlDoc            ' XML DOM object
Dim xslDoc            ' XML DOM object for Stylesheet
Dim xslTemplate       ' Template cache object
Dim xslProc           ' Rental threaded template processor
Dim sHTML             ' HTML string variable
Dim sRequest          ' String value of request
Dim bRequest          ' Boolean to flag when XML save needed
Dim iNumItems         ' Number of news items to show from each source
Dim bLoad             ' Make sure the xml doc was loaded successfully
Dim oFileSys          ' File system object for checking xml modification date
Dim oFileNews         ' object for XML_News file
Dim oFileHack         ' object for XML_Hack file

' Initialize variables
    Set xmlDoc = Server.CreateObject("MSXML2.DOMDocument")
        xmlDoc.async = false
        xmlDoc.setProperty "ServerHTTPRequest", true

' Check to see how stale the cached news file is
    Set oFileSys = CreateObject("Scripting.FileSystemObject")
    Set oFileNews = oFileSys.GetFile(Server.MapPath("/UXCodeStandards/Data/XML/feeds/xml/XML_News.xml"))
    Set oFileHack = oFileSys.GetFile(Server.MapPath("/UXCodeStandards/Data/XML/feeds/xml/XML_Hack.xml"))
    if    DateDiff("n",oFileNews.DateLastModified,Now()) > 2 then
        sRequest = "http://p.moreover.com/cgi-local/page?index_xml+rss"
        bLoad = xmlDoc.load(sRequest)
        ' only update the server if the load was successfull
        if bLoad then
            xmlDoc.save(oFileNews.Path)
        end if
        sRequest = "http://xmlhack.com/rss.php"
        bLoad = xmlDoc.load(sRequest)
        ' only update the server if the load was successfull
        if bLoad then
            xmlDoc.save(oFileHack.Path)
        end if
    end if


Set xslDoc = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
    xslDoc.async = false
    bLoad = xslDoc.load(Server.MapPath("/UXCodeStandards/Data/XML/feeds/xsl/XML_News.xsl"))
Set xslTemplate = Server.CreateObject("MSXML2.XSLTemplate")
    xslTemplate.stylesheet = xslDoc




    if Err.number then
        'Error Handler
        xmlDoc.loadXML("<Error/>")    'Clears out the XML doc for use in error reporting
        'create the Error Attributes
        xmlDoc.documentElement.setAttribute "Err_Number", Err.number
        xmlDoc.documentElement.setAttribute "Err_Description", Err.description
        xmlDoc.documentElement.setAttribute "Err_Source", Err.source

        Response.ContentType = "text/xml"
        Response.Write(xmlDoc.xml)
    else
'    If no error, Write the Response
        ' Set the number of items to show
        If Request.QueryString("XML_News") <> "" Then
            iNumItems = 26
        Else
            iNumItems = 6
        End If
        sRequest =     oFileNews.Path
        bLoad = xmlDoc.load(sRequest)
        set xslProc = xslTemplate.createProcessor
            xslProc.input = xmlDoc
            xslProc.addParameter "newsName", "XML_News"
            xslProc.addParameter "numItems", iNumItems
            xslProc.transform
        sHTML = xslProc.output
        Response.Write sHTML

        If Request.QueryString("XML_Hack") <> "" Then
            iNumItems = 26
        Else
            iNumItems = 6
        End If
        sRequest =     oFileHack.Path
        bLoad = xmlDoc.load(sRequest)
        set xslProc = xslTemplate.createProcessor
            xslProc.input = xmlDoc
            xslProc.addParameter "newsName", "XML_Hack"
            xslProc.addParameter "numItems", iNumItems
            xslProc.output = Response
            xslProc.transform
    end if

%>

rdcpro:

correct me if I have this wrong, but rss seems to be a 1 way solution

I'm looking for more towards a 2way stream

$serverB has forms which users select <what ever> which has a 'ID' that is then passed along to $severA

which is then processed and the results are displayed on $serverB

This is driving me crazy, I know when this is all said and done (providing I get something working) I'm going to either shoot myself (not really) or slap myself crazy for not seeing the solution
Well, it's an HTTP request, so it's always two-way...it's a request/response mechanism.  You can POST or GET, or whatever.  If you look at the sample URL above, it looks like:

http://p.moreover.com/cgi-local/page?index_xml+rss

So this sends certain parameters to the datasource...in this case it's a cgi script, called "page" and the parameters being passed are index_xml+rss, but in your case it would work similarly.

Now, you're not trying to update the datasource from the client, are you?  You just need to send the ID so that server A can get the correct data?

Regards,
Mike Sharp
the results obtained from server A will be used as optional update data for server B yes.

basicly Sever A is nothing more than a data warehouse for Server B

the end result will be used for printing by the user at Server B

I'm starting to wonder if I'm going about this the wrong way

rdcpro,
ken has mentioned that serverB does not have scripting capabilities, and it is not IIS but a unix server (running Apache?).

kenfcamp,
The XMLHTTP method I mentioned is client based, so the client receives the HTML page from serverB, and the HTML page contains javascript to get the XML data from serverA using XMLHTTP.
You will have to add some scripting to the HTML page.

The problem is how to get both appear from the same domain to the client, and if you do have apache on serverB it is actually quite simple.
Apache can serve as a reverse proxy, in effect mapping a remote serverA to a virtual directory on serverB.
It does mean changing a few lines in serverB's configuration.
look here for an example (the accepted answer).
https://www.experts-exchange.com/questions/20674148/Ensure-PDF-security-from-cutting-and-pasting-location-URL.html
shalomc:

Interesting concept.

1) Sever B is going to be unknown but is more than likely IIS , it just happens to be Apache for testing

2) There is no way the owners of Server B is going to reconfigure just for this.
shalomc:

xmhttp does work when used on server A

but when the same script is used on server B it errors with permission denied
kenfcamp,
The permission denied error is due to security settings in Explorer, which are totally out of your control.

If ServerB is IIS, can you ask them to install an ASP similar to the one provided by rdcpro ?

ShalomC
shalomc

right now both A and B are Apache.

The script works on A , but not on B

looks like that's not going to work then lol
yes,
If serverB cannot (or will not) neither install a script (PHP or ASP) nor alter the configuration, then it's not going to work.
Do try to alter the current serverB according to my suggestion just to see if it works.

ShalomC
unfortunatly that's part of the problem (why I posted the question in the first place)

soap or even wddx should be simple enough for this, but want to do it the hard way :\

serverB will be unwilling to make any modifications.

I need a beer
ASKER CERTIFIED SOLUTION
Avatar of rdcpro
rdcpro
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial