Jump to content

XML Newbie (again)


awebbdesign

Recommended Posts

I need the following XML code http://primarymortgages.co.uk/dev/property-xml-donotdelete.xml to be entered into the database, while I have done the first bit...

 

<code>

# address - basic info

if(is_object($xml->address)) {

foreach($xml->address as $address) {

$name = $address->name;

$street = $address->street;

$locality = $address->locality;

$town = $address->town;

$county = $address->county;

$postcode = $address->postcode;

$custom_location = $address->custom_location;

$display = $address->display;

$insertS = "INSERT INTO $tablec (pal, afield, bfield, cfield, dfield, efield, ffield, hfield, ifield, jfield) VALUES

(110, '$bD->afield', '$name', '$street', '$locality', '$town', '$county', '$postcode', '$custom_location', '$display')";

$insertQ = mysql_query($insertS);

$iid = mysql_insert_id();

}

}

 

# property - basic info

if(is_object($xml)) {

$long = $xml->longitude;

$lat = $xml->latitude;

$type = $xml->type;

$furnished = $xml->furnished;

$bedrooms = $xml->bedrooms;

$bathrooms = $xml->bathrooms;

$description = $xml->description;

$updateS = "UPDATE $tablec SET

kfield = '$long',

lfield = '$lat',

mfield = '$type',

nfield = '$furnished',

ofield = '$bedrooms',

pfield = '$bathrooms',

atext = '$description'

WHERE pal = 110

AND id = $iid";

$updateQ = mysql_query($updateS);

}

</code>

 

I need to be able to get the paragraphs...

 

<paragraph id="1" type="0">

<name>DESCRIPTION</name>

<file /><dimensions>

<metric />

<imperial />

<mixed />

</dimensions>

<text>Primary are pleased to offer this two bedroom first floor maisonette in Wootton Bassett. The accommodation comprises of private entrance hall, lounge, kitchen, two bedrooms and bathroom. The property also benefits from uPVC double glazing, central heating and two allocated parking spaces. No onward chain.</text>

</paragraph>

<paragraph id="2" type="0">

<name>PRIVATE ENTRANCE PORCH</name>

<file />

<dimensions>

<metric />

<imperial />

<mixed />

</dimensions>

<text>Storage cupboard.</text>

</paragraph>

<paragraph id="3" type="0">

<name>PRIVATE ENTRANCE HALL</name>

<file />

<dimensions>

<metric />

<imperial />

<mixed />

</dimensions>

<text>Stairs leading to first floor. Radiator.</text>

</paragraph>

 

etc, etc... However the following code isn't working for me...

 

<code>

# paragraphs

print_r ($xml->paragraph);

foreach($xml->paragraph as $paragraph) {

$thetitle = $paragraph->title;

$thetext = $paragraph->text;

$insertS = "INSERT INTO $tablec (pal, afield, bfield, atext) VALUES (111, '$iid', '$thetitle', '$thetext')";

$insertQ = mysql_query($insertS);

print "<p>$insertS</p>";

 

}

</code>

 

Can someone adjust the # paragraphs code for me so it can work

 

Many Thanks.

Link to comment
Share on other sites

guess this would be helpful

<?php
$file = "x.xml";
$doc = new DOMDocument();
$doc->load( "$file" );
$results = $doc->getElementsByTagName( "paragraph" );
foreach( $results as $result )
{
  $pgraphs= $result->getElementsByTagName( "name" );
  $pgraph = $pgraphs->item(0)->nodeValue;
  print "Name => ".$pgraph."<br/>";
  
  $ptexts= $result->getElementsByTagName( "text" );
  $ptext = $ptexts->item(0)->nodeValue;
  print "text => ".$ptext."<br/>";
  print "<br>--------------------------------------------------<br>";
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.