Xpath,php and jquery validation script
<p>I'm create a deal agregator but first i need to put xpath into database but before that I need to type xpath and website into my fields to see what result I will get... so some type of xpath validation tool:</p>

<p>Here is my code for type xpath adresses into textfields:</p>

<p>xpathadd.html</p>

<pre><code>&lt;!DOCTYPE HTML&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset="utf-8"&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;script src="http://code.jquery.com/jquery-latest.min.js"
        type="text/javascript"&gt;&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;
&lt;script&gt;
addToDatabase = function() {
    alert("addToDatabase called");
    $.post("generatingxpath.php", {
        websource: $('#websource').val(),
        links: $('#links').val(),
        title: $('#title').val(),
        image: $('#image').val(),
        discount: $('#discount').val(),
        price: $('#price').val(),
        description: $('#description').val(),
        coordinates: $('#coordinates').val()
    }, function(data) {
        $("#result").html(data);
    });
};​
&lt;/script&gt;
&lt;form name="form1" method="post" action="generatingxpath.php"&gt;

  &lt;p&gt;
    &lt;label for="websource"&gt;&lt;/label&gt;
    Web source:
    &lt;input name="websource" type="text" id="websource" size="70"&gt;
  is:&lt;/p&gt;
  &lt;p&gt;

    &lt;label for="links"&gt;&lt;/label&gt;
    Links:
    &lt;input name="links" type="text" id="links" size="77"&gt;
    OK!
  &lt;/p&gt;
  &lt;p&gt;

    &lt;label for="title"&gt;&lt;/label&gt;
    Title:
    &lt;input name="title" type="text" id="title" size="78"&gt;
  is:&lt;/p&gt;
  &lt;p&gt;

    &lt;label for="image"&gt;&lt;/label&gt;
    Image:
    &lt;input name="image" type="text" id="image" size="76"&gt;
  show:&lt;/p&gt;
  &lt;p&gt;

    &lt;label for="discount"&gt;&lt;/label&gt;
    Disscount:
    &lt;input name="discount" type="text" id="discount" size="72"&gt;
  is:&lt;/p&gt;
  &lt;p&gt;

    &lt;label for="price"&gt;&lt;/label&gt;
    Price:
    &lt;input name="price" type="text" id="price" size="77"&gt;
  is:&lt;/p&gt;
  &lt;p&gt;

    &lt;label for="description"&gt;&lt;/label&gt;
    Desription:
    &lt;input name="description" type="text" id="description" size="72"&gt;
  is:&lt;/p&gt;
  &lt;p&gt;

    &lt;label for="coordinates"&gt;&lt;/label&gt;
    Coordinates:
    &lt;input name="coordinates" type="text" id="coordinates" size="70"&gt;
  lat,lng is:&lt;/p&gt;
  &lt;p&gt;
    &lt;input type="submit" name="Submit" id="Submit" value="Preview"&gt;
or
&lt;input type="submit" name="Add to database" id="Add to database" value="Add To Database"&gt;
&lt;a href="javascript:addToDatabase();"&gt;Add to database&lt;/a&gt;
  &lt;/p&gt;
  &lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;/form&gt;
    &lt;div id="result"&gt;&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;​
</code></pre>

<p>and generatingxpath.php</p>

<pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;

&lt;html&gt;

&lt;head&gt;

&lt;title&gt;GENERATING XPATH&lt;/title&gt;

&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8"&gt;

&lt;/head&gt;



&lt;body&gt;

&lt;?php


function curl($url){

        $ch = curl_init();

        curl_setopt($ch, CURLOPT_URL, $url);

        curl_setopt($ch, CURLOPT_ENCODING, "gzip");

        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

        $data = curl_exec($ch);

        curl_close($ch);

        return $data;

}



libxml_use_internal_errors(true);


$websource = $_POST["websource"];
$links = $_POST["links"];
$title = $_POST["title"];
$image = $_POST["image"];
$disscount = $_POST["disscount"];
$price = $_POST["price"];
$description = $_POST["description"];
$coordinates = $_POST["coordinates"];


//start generating xpath script

$dom = new DOMDocument(); 

@$dom-&gt;loadHTMLFile($websource); 

$xpath = new DOMXPath($dom); 

$entries = $xpath-&gt;query($links);

$output = array(); 

$i = 1;

foreach($entries as $e) {   

  $dom2 = new DOMDocument(); 

  @$dom2-&gt;loadHTMLFile($websource . $e-&gt;textContent); 

  $xpath2 = new DOMXPath($dom2); 

  $data = array();

  $data['websource']= ($websource . $e-&gt;textContent);

  $data['title'] = trim($xpath2-&gt;query($title)-&gt;item(0)-&gt;textContent); 

  $data['description'] = trim($xpath2-&gt;query($description)-&gt;item(0)-&gt;textContent); 

  $data['image'] = trim($xpath2-&gt;query($image)-&gt;item(0)-&gt;textContent); 

  $string = $xpath2-&gt;query($coordintes)-&gt;item(1)-&gt;textContent; 

  preg_match_all('#(([0-9-]+){1,3}.([0-9]+))#is', $string, $matches); 

  $data['lat']=$matches[1];
  $data['lng']=$matches[2];
  $data['disscount'] = trim($xpath2-&gt;query($disscount)-&gt;item(0)-&gt;textContent);
    $data['price'] = trim($xpath2-&gt;query($price)-&gt;item(0)-&gt;textContent);


//print to see that all is fine or need to change some xpath direction

  echo $data['websource'];
  echo $data['links'];
  echo $data['title'];
  echo $data['image'];
  echo $data['disscount'];
  echo $data['price'];
  echo $data['lat'];
  echo $data['lng'];
  echo $data['description'];


    $output[] = $data; 



} 



?&gt;

&lt;/body&gt;

&lt;/html&gt;
</code></pre>

<p>but I get only Warning: Invalid argument supplied for foreach() in /home/pluspon/public_html/test/generatingxpath.php on line 67
??? WHY? where is problem?</p>
