我试图验证我的XML,但我没有得到正确的回复,有人告诉我如何验证我的后期操作?什么是批量发布的方式,没有类别和位置?
我在Craigslist有免费帐户。我使用这段代码:
<?php error_reporting(E_ALL);
ini_set('display_errors', '1');
$name='my username';//$_POST['name']; // Get from form or get from DB one per xml
$password= 'my password';//$_POST['password'];
$id='my account ID';//$_POST['id'];
$xmlStart='<?xml version="1.0"?>
<rdf:RDF xmlns="http://purl.org/rss/1.0/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cl="http://www.craigslist.org/about/cl-bulk-ns/1.0">';
$channelStart='<channel>';
$channelItems='<items>';
$channelItemsEnd='</items>';
$channelAuth='<cl:auth username="'.$name.'"
password="'.$password.'"
accountID="'.$id.'"/>';
$channelEnd='</channel>';
$xmlEnd='</rdf:RDF>';
$channelItems .='<rdf:li rdf:resource="$179000 / 3br - 3 Bed/1 Bath Great NE Heights Locating!! No Bank Qualifying!! Owner Fi (NE Albuquerque)"/>';
$items='';
//set the content type to xml
//header("Content-Type: text/xml");
// Initialize the xmlOutput variable
$xmlBody = '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody = '<rdf:RDF xmlns="http://purl.org/rss/1.0/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:cl="http://www.craigslist.org/about/cl-bulk-ns/1.0">';
$xmlBody .= "<XML>";
// Run a select query to get my letest 6 items
// Connect to the MySQL database
mysql_connect("localhost","root","");
mysql_select_db('new_listing');
//$dynamicList = "";
$sql = mysql_query("SELECT * FROM listing ORDER BY id");
$productCount = mysql_num_rows($sql); // count the output amount
if ($productCount > 0) {
while($row = mysql_fetch_array($sql)){
// Create channel item string
$channelItems .='';
$id = $row['id'];
$name = $row['username'];
$password= $row['password'];
$address = $row['address'];
$Posting_type = $row['posting_type'];
$category = $row['category'];
$location = $row['location'];
$posting_title = $row['posting_title'];
$specific_loc = $row['specific_loc'];
$postal = $row['postal_code'];
$description = $row['description'];
$reply_to = $row['reply_to'];
$rent = $row['rent'];
$sqft = $row['sqft'];
$bedrooms = $row['bedrooms'];
$bathrooms = $row['bathrooms'];
$housing = $row['housing_type'];
$laundry = $row['laundry'];
$parking = $row['parking'];
$wheelchair = $row['wheelchair'];
$smoking = $row['smoking'];
$furnished = $row['furnished'];
$street = $row['street'];
$cross_street = $row['cross_street'];
$city = $row['city'];
$zip_code = $row['zip_code'];
$date_d = $row['date_d'];
$time_t = $row['time_t'];
$image = $row['images'];
$items .= '
<item rdf:about="real estate">
<cl:category>"housing"</cl:category>
<cl:area>"NE Albuquerque"</cl:area>
<cl:housingInfo price="$179000"
bedrooms="3"
sqft="1400"/>
<cl:replyEmail privacy="C">email address</cl:replyEmail>
<cl:brokerInfo companyName="Your Company name"
feeDisclosure="fee disclosure here" />
<title>"$179000 / 3br - 3 Bed/1 Bath Great NE Heights Locating!! No Bank Qualifying!! Owner Fi (NE Albuquerque)"</title>
<description><![CDATA["3 Bedroom, 1 Bath 1400sqft home with 1 car garage,
Lease With Option To Buy, No Bank Qualifying!!
Price $179,000, $1200 lease per month + $15,000 down
Great Location in NE Heights close to schools, shopping and jobs!!
Very Desirable Location! Call 505-264-7942 and ask for Robert"]]></description>
</item>';
// End while loop
}
mysql_close();
// close the mysql database connection
//$xmlBody .= "</XML>";
$xmlToSubmit=$xmlStart.$channelStart.$channelItems.$channelAuth.$channelItemsEnd.$channelEnd.$items.$xmlEnd;
class cURL {
var $headers;
var $user_agent;
function cURL()
{
$this->headers[] = 'Connection: Keep-Alive';
$this->headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8';
$this->user_agent = 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)';
}
function post($url,$data) {
$process = curl_init($url);
curl_setopt($process, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($process, CURLOPT_HEADER, 1);
curl_setopt($process, CURLOPT_USERAGENT, $this->user_agent);
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_POSTFIELDS, $data);
curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($process, CURLOPT_POST, 1);
$return = curl_exec($process);
$info = curl_getinfo($process);
curl_close($process);
return $info;
}
}
$cc = new cURL();
$url = 'https://post.craigslist.org/bulk-rss/post';
$output = $cc->post($url,$xmlToSubmit);
//echo $output;
print_r($output);
} ?>