开发者

Case Study: Can this be achieved in PHP, JQuery or Ajax. Pulling different Structured XMLs and display it in just one page simultaneously!

thanks in advance for those who will lend their time answering this question.

I’m trying to display two external XML data into my page. Let us say the fictional location of these XMLs are www.ExampleDomain1.com/xml-1.xml and www.ExampleDomain2.com/xml-2.xml respectively. The two XMLs have different element tags but have common contents, here's the example:

XML-1.xml

<property>
 <type>SP</type>
 <subtype>Apartment</subtype>
 <refno>011248</refno>
 <title>Fantastic Facilities!</title>
 <description> Offering this fantastic 2 bedroom apartment set within this popular building in The Views. The property offers in excess of 1450sqft of internal living space comprising of two double bedrooms (en-suite to master),  fitted kitchen with integrated appliances, main bathroom and spacious lounge/diner leading onto a good size balcony with partial views of the golf course and views of the Marina skyline.
 </description>
 <size>1458</size>
 <sizeunits>SqFt</sizeunits>
 <price>1525000</price>
 <pricecurrency>AED</pricecurrency>
 <totalclosingfee>1525000</totalclosingfee>
 <bedrooms>2</bedrooms>
 <bathrooms>2</bathrooms>
 <locationtext>The Views</locationtext>
 <locationlat>25.090200</locationlat>
 <locationlon>55.170200</locationlon>
 <developer>0</developer>
 <lastupdated>2011-02-18 20:15:08</lastupdated>
 <photos>
  <photo>
http://www.ExampleDomain1.com/images/med_imgga94jqe351494b66b20eaec11fe501f5bdf797f4.jpg
  </photo>
  <photo>
http://www. ExampleDomain1.com/images/med_imgga94l1maf3ccdd27d2000e3f9255a7e3e2c48800.jpg
  </photo>
 </photos>
</property>

XML-2.xml

<listings>
 <category>SP</category>
 <subcategory>Apartment</ subcategory >
 <reference>011250</reference>
 <title>Fantastic Facilities!</title>
 <description> A fantastic 1 bedroom apartment in the exclusive Downtown area. The property offers 850 sq.ft. of internal living space. Fantastic layout and personalized design. Externally the property has an easy accessible carport with parking for one. 
 </description>
 <size>1200</size>
 <unitsize>SqFt</ unitsize >
 <price>905000</price>
 <currency>AED</currency>
 <closingfee>1525000</closingfee>
 <bedrooms>2</bedrooms>
 <bathrooms>2</bathrooms>
 <location> Downtown </location>
 <locationlon>55.170200</locationlon>
 <developer>0</developer>
 <updated>2011-02-18 20:15:08</updated>
 <photos>
   <photo> http://www.ExampleDomain2.com/images/med_imgga94jqe351494b66b20eaec11fe501f5bdf797f4.jpg
   </photo>
   <photo> http://www. ExampleDomain2.com/images/med_imgga94l1maf3ccdd27d2000e3f9255a7e3e2c48800.jpg
    </photo>
 </photos>
</listings>

From the above example you can clearly see that the XML tags varied differently though both have same contents. Someone will say why not clean the XML before fetching it? The problem is both XMLs were produced by proprietary software which do not have an option to manipulate the output. So matching the element tags first is not viable besides it will be a huge task for me if I will开发者_如何学JAVA do it manually especially if the data are big.

To make things more complicated, I want to fetch both XMLs and display both results together in just one page. I want to load both XMLs simultaneously and display it in a search result.

I’ve been burning my eyes for a week now and the closest code example I’ve found was this http://net.tutsplus.com/tutorials/javascript-ajax/use-jquery-to-retrieve-data-from-an-xml-file/. The problem with this code example is that it loads only one XML from local directory. What if I want to load many XMLs at once from external source?

To elaborate more what exactly I want to achieve are these:

  1. Make a search form that will get both XMLs and display it in just one page.

  2. Make the image appear as the code example from the tutorial above is different from the XML structure that I have.

  3. What application that I must know to accomplish this case (PHP or JQuery or AJAX or combination of three?).

  4. Can it be achieved even if the XMLs would not be stored in a database?

As a newbie in coding PHP and just following some Jquery script examples, without your help the above problem will took me ages before I could find out the right solution. I’m confident in HTML and CSS but not in programming side.

Can you please help me show the path that I need to follow on (example codes)? Or is there someone Genius out there that could throw me the exact SCIENTFIC codes that I’m looking for?

Many thanks,

Mike


Ok. THAT seems to be quite complicated. But actually you can achieve this with a medium amount of work. I will not provide you with any code or examples right now but show the possibilities how you can solve that problem.

First things first. You can do it with Javascript/jQuery only. This would mean that the client has lots of work and fetching to do, but it is possible.

You can also do it with a combination of PHP an JS. This would mean that the server would do the heavy work to fetch and match the data and send a combined result back to the client.

If it is always the same date the PHP solution has a major advantage. You could cache the combined data so you could save time matching the XML every time.

Just think about what will work better for you and we can help you coding for stuff. (Just to get clear: The XML always looks like the examples you provided? The fields/tags in the XML are always the same? If not the entire thing is much more complicated.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜