|
xml, php
Hello, I have an xml parser script that works great.. but I am having a small problem:
When I use <company_name>Sample Company</company_name> in the .xml file, it works great.. but I get the .xml file in this format: <company_name><![CDATA[Sample Company]]></company_name>
Is there a way to remove <![CDATA[ ]]> and simply have "Sample Company between the <company_name></company_name> ? I've tried with ereg_replace but I'm getting an error.
Thanks,
Cedric
PHP Code:
<?
// Extracts content from XML tag
function GetElementByName ($xml, $start, $end) {
global $pos;
$startpos = strpos($xml, $start);
if ($startpos === false) {
return false;
}
$endpos = strpos($xml, $end);
$endpos = $endpos+strlen($end);
$pos = $endpos;
$endpos = $endpos-$startpos;
$endpos = $endpos - strlen($end);
$tag = substr ($xml, $startpos, $endpos);
$tag = substr ($tag, strlen($start));
return $tag;
}
// Open and read xml file. You can replace this with your xml data.
$file = "SampleXML2.xml";
$pos = 0;
$Nodes = array();
if (!($fp = fopen($file, "r"))) {
die("could not open XML input");
}
while ($getline = fread($fp, 4096)) {
$data = $data . $getline;
}
$count = 0;
$pos = 0;
// Goes throw XML file and creates an array of all <XML_TAG> tags.
while ($node = GetElementByName($data, "<job>", "</job>")) {
$Nodes[$count] = $node;
$count++;
$data = substr($data, $pos);
}
// Gets infomation from tag siblings.
for ($i=0; $i<$count; $i++) {
$job_title = GetElementByName($Nodes[$i], "<job_title>", "</job_title>");
$reference_number = GetElementByName($Nodes[$i], "<reference_number>", "</reference_number>");
$contact_url = GetElementByName($Nodes[$i], "<contact_url>", "</contact_url>");
$company_industry = GetElementByName($Nodes[$i], "<company_industry>", "</company_industry>");
$city = GetElementByName($Nodes[$i], "<city>", "</city>");
echo " $job_title, $reference_number, $contact_url, $company_industry, $city yea!<br><br>";
}
?>
PHP Code:
<jobs>
<job>
<action><![CDATA[Add]]></action>
<partner_id><![CDATA[Sample]]></partner_id>
<reference_number><![CDATA[J03YZ1MKK8NBKSHQZN]]></reference_number>
<job_info>
<company_name><![CDATA[Sample Company]]></company_name>
<company_description><![CDATA[]]></company_description>
<company_industry><![CDATA[Other / Not Specified]]></company_industry>
<job_title><![CDATA[Registration Clerk]]></job_title>
<job_description><![CDATA[Kforce has an open position for a Registration Clerk located in the metropolitan area of St. Louis, MO.Responsibilities: Registration Clerk for fast paced hospital environment environment. please visit our web site at <a href="http://www.kforce.comJob" target="_blank">[url]www.kforce.comJob[/url]</a> Ref#: 1137~SLM~4394B1~17]]></job_description>
<required_skills><![CDATA[Must have at least 12 months related experience in registration or admissions and discharge related work]]></required_skills>
<job_category><![CDATA[Healthcare, Practitioner and Technician]]></job_category>
<full_part><![CDATA[Parttime]]></full_part>
<job_type><![CDATA[Contract]]></job_type>
<salary_range><![CDATA[]]></salary_range>
<salary_value><![CDATA[]]></salary_value>
<benefits><![CDATA[]]></benefits>
<education><![CDATA[]]></education>
<experience><![CDATA[]]></experience>
</job_info>
<location>
<country><![CDATA[US]]></country>
<city><![CDATA[Saint Louis]]></city>
<state_province><![CDATA[MO]]></state_province>
<address1><![CDATA[]]></address1>
<address2><![CDATA[]]></address2>
<zip_code><![CDATA[63101]]></zip_code>
<area_code><![CDATA[]]></area_code>
</location>
<contact>
<contact_name><![CDATA[None Specified]]></contact_name>
<contact_email><![CDATA[Email@sample.com]]></contact_email>
<contact_phone><![CDATA[]]></contact_phone>
<contact_fax><![CDATA[]]></contact_fax>
<contact_url><![CDATA[<a href="http://www.careerbuilder.com/jobseeker/jobs/JobDetails.asp?did=J03YZ1MKK8NBKSHQZN" target="_blank">[url]http://www.careerbuilder.com/jobsee...YZ1MKK8NBKSHQZN[/url]</a>]]></contact_url>
</contact>
</job>
<job>
<action><![CDATA[Add]]></action>
<partner_id><![CDATA[Sample]]></partner_id>
<reference_number><![CDATA[J201774Z1MC3YQLZ4N]]></reference_number>
<job_info>
<company_name><![CDATA[Sample Company]]></company_name>
<company_description><![CDATA[]]></company_description>
<company_industry><![CDATA[Finacial Services and Insurance]]></company_industry>
<job_title><![CDATA[Field Claim Specialist]]></job_title>
<job_description><![CDATA[ERC, a global leader in reinsurance & subsidiary of GE, has an excellent career opportunity. We offer a competitive salary, outstanding benefits & professional advantages of an environment the above position, please reference GECERC/291380/WB337 on the subject line of your e-mail message.]]></required_skills>
<job_category><![CDATA[Other]]></job_category>
<full_part><![CDATA[Fulltime]]></full_part>
<job_type><![CDATA[Permanent]]></job_type>
<salary_range><![CDATA[]]></salary_range>
<salary_value><![CDATA[]]></salary_value>
<benefits><![CDATA[]]></benefits>
<education><![CDATA[Master's Degree]]></education>
<experience><![CDATA[More than 5 Years]]></experience>
</job_info>
<location>
<country><![CDATA[US]]></country>
<city><![CDATA[Cleveland]]></city>
<state_province><![CDATA[OH]]></state_province>
<address1><![CDATA[]]></address1>
<address2><![CDATA[]]></address2>
<zip_code><![CDATA[44101]]></zip_code>
<area_code><![CDATA[]]></area_code>
</location>
<contact>
<contact_name><![CDATA[None Specified]]></contact_name>
<contact_email><![CDATA[Email@sample.com]]></contact_email>
<contact_phone><![CDATA[]]></contact_phone>
<contact_fax><![CDATA[]]></contact_fax>
<contact_url><![CDATA[]]></contact_url>
</contact>
</job>
<job>
<action><![CDATA[Add]]></action>
<partner_id><![CDATA[Sample]]></partner_id>
<reference_number><![CDATA[J201D76HNFJXZQ4QGL]]></reference_number>
<job_info>
<company_name><![CDATA[Sample Company]]></company_name>
<company_description><![CDATA[]]></company_description>
<company_industry><![CDATA[Health Services]]></company_industry>
<job_title><![CDATA[Cardiovascular Surgical Services Coordinator]]></job_title>
<job_description><![CDATA[Must have a current Texas RN licensure and CPR certification. ACLS certification required within 6 months and CNOR required within 1 year of employment. Membership into the Association of retirement, vacation, holidays, sick pay, long/short term disability, and tuition reimbursement.]]></job_description>
<required_skills><![CDATA[See job description above.keywords: rn, r.n., nurse, nursing, hospital, medical, healthcare, surgery, cardiovascular, operating room, Cardio Thoracic, acls, cnor,]]></required_skills>
<job_category><![CDATA[Healthcare, Practitioner and Technician]]></job_category>
<full_part><![CDATA[Fulltime]]></full_part>
<job_type><![CDATA[Permanent]]></job_type>
<salary_range><![CDATA[]]></salary_range>
<salary_value><![CDATA[]]></salary_value>
<benefits><![CDATA[]]></benefits>
<education><![CDATA[Associates Degree]]></education>
<experience><![CDATA[At Least 1 Year]]></experience>
</job_info>
<location>
<country><![CDATA[US]]></country>
<city><![CDATA[Denison]]></city>
<state_province><![CDATA[TX]]></state_province>
<address1><![CDATA[]]></address1>
<address2><![CDATA[]]></address2>
<zip_code><![CDATA[75020]]></zip_code>
<area_code><![CDATA[]]></area_code>
</location>
<contact>
<contact_name><![CDATA[Joni Horn]]></contact_name>
<contact_email><![CDATA[Email@sample.com]]></contact_email>
<contact_phone><![CDATA[(903) 416-4051]]></contact_phone>
<contact_fax><![CDATA[(903) 416-40]]></contact_fax>
<contact_url><![CDATA[]]></contact_url>
</contact>
</job>
</jobs>
|