aspguy Posted July 7, 2007 Share Posted July 7, 2007 I want to be able to search xml document (using it as a db) and display the results out of it. i've done that in aspx before, and have the code for it. i am new to php and want some help in this regard. thanks in advance. my xml document looks like this: <?xml version="1.0" encoding="UTF-8" ?> - <listings> - <listing linkId="65892"> <streetno>16</streetno> <street>Pine Grove Road</street> <price>799000.0000</price> <area areaId="135" abr="Mid" name="Mid Island" /> <lotSize>0.2400</lotSize> <listType typeCode="MF" typeName="Multi-Family" /> <furnished furnishedType="345" abr="Un/F" description="Un-Furnished" /> - <firm firmId="508"> <firmName>xxxx</firmName> <phone>12345</phone> </firm> <zoning>R10</zoning> <water>Town</water> <sewer>Town</sewer> <EasementDesc>-</EasementDesc> <waterFrontage>None</waterFrontage> <waterViews>None</waterViews> <otherViews>None</otherViews> <leadPaint>No</leadPaint> <secondDwelling>None</secondDwelling> <yearBuilt>1985</yearBuilt> <yearRenovated>0</yearRenovated> <rooms>8</rooms> <beds>5</beds> <baths>3</baths> <halfBaths>0</halfBaths> <firstFloorBeds>1</firstFloorBeds> <flooringType>Carpet/Linoleum</flooringType> <heatType>Electric</heatType> <yardType>Yes</yardType> <foundationType>Block</foundationType> <descMain>Cute Cape - Currently used as an income producing duplex this cute Cape can be converted to a single family, five bedroom three bath home. This property is nestled on a wooded lot overlooking Land Bank property.</descMain> <descParking>Yes</descParking> <descBasement>Downstairs Unit: Living, kitchen, dining. Two bedrooms, bath(T/S), stack washer/dryer.</descBasement> <descFloor1>Upstairs Unit: First Floor: Living room, dining area overlooking private deck, kitchen. One bedroom, hall bath(T/S) and washer/dryer.</descFloor1> <descFloor2>Upstairs Unit Second Floor: Two bedrooms share a hall bath(S).</descFloor2> <desc2ndDwelling /> <DishwasherType>Yes</DishwasherType> <DryerType>Yes</DryerType> <FridgeType>Yes</FridgeType> <StoveType>yes</StoveType> <TvType>Cable</TvType> <WasherType>Yes</WasherType> - <photos> <photo photoID="940" PhotoNum="1.0" /> <photo photoID="2813" PhotoNum="2.0" /> </photos> </listing> so far, my accomplishment on asp are as follows: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>IDX Feed</title> </head> <body> <form id="form1" runat="server"> <div> <asp:XmlDataSource ID="IDXData" runat="server" DataFile="~/IDXFeed.xml"></asp:XmlDataSource> </div> <asp:Repeater ID="rListings" runat="server" DataSourceID="IDXData"> <HeaderTemplate> Listings </HeaderTemplate> <ItemTemplate> <table> <tr> <td valign="top" ><img alt="photo" src='<%# GetSetting("IDXImageHandler") + "?id=" + XPath("photos/photo/@photoID") + "&w=150&thumb=yes"%>' /></td> <td valign="top" > <table> <tr><td>Type:</td><td><%# XPath("listType/@typeName") %></td></tr> <tr><td>Address:</td><td><%# XPath("streetno") + " " + XPath("street") %></td></tr> <tr><td>Town:</td><td><%# XPath("area/@name") %></td></tr> <tr><td>Price:</td><td><%# Decimal.Parse((string)XPath("price")).ToString("C0") %></td></tr> <tr><td>Bedrooms:</td><td><%# XPath("beds") %></td></tr> <tr><td>Bathrooms:</td><td><%# XPath("baths") %></td></tr> <tr><td valign="top">Description:</td><td><%# XPath("descMain") %></td></tr> </table> </td> </tr> </table> </ItemTemplate> </asp:Repeater> </form> </body> </html> i want some help to be able to duplicate this in php. thanks in advance Link to comment https://forums.phpfreaks.com/topic/58818-parsing-xml-in-php/ Share on other sites More sharing options...
Barand Posted July 7, 2007 Share Posted July 7, 2007 this should get you going <?php $xml = simplexml_load_file('myxml.xml'); foreach ($xml->listing as $list) { echo "<table border='1' width='500'>\n"; echo "<tr><th>Type</th><td>{$list->listType['typeName']}</td></tr>\n"; echo "<tr><th>Address</th><td>$list->streetno $list->street</td></tr>\n"; echo "<tr><th>Town</th><td>{$list->area['name']}</td></tr>\n"; echo "<tr><th>Price</th><td>\$" . number_format($list->price, 0) . "</td></tr>\n"; echo "<tr><th>Beds</th><td>$list->beds</td></tr>\n"; echo "<tr><th>Baths</th><td>$list->baths</td></tr>\n"; echo "<tr><th>Description</th><td>$list->descMain</td></tr>\n"; echo "</table>\n"; } ?> Link to comment https://forums.phpfreaks.com/topic/58818-parsing-xml-in-php/#findComment-291825 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.