XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old February 11th, 2004, 07:04 AM
syncedit syncedit is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 syncedit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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 ($tagstrlen($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($fp4096)) { 
   
$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 StLouisMO.ResponsibilitiesRegistration Clerk for fast paced hospital environment environmentplease visit our web site at <a href="http://www.kforce.comJob" target="_blank">[url]www.kforce.comJob[/url]</aRef#: 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[HealthcarePractitioner 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[ERCglobal leader in reinsurance subsidiary of GEhas an excellent career opportunityWe offer a competitive salaryoutstanding benefits professional advantages of an environment the above positionplease 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> 

Reply With Quote
  #2  
Old February 12th, 2004, 12:52 AM
bricker42 bricker42 is offline
Moderator =(8^(|)
Dev Shed Intermediate (1500 - 1999 posts)
 
Join Date: Feb 2002
Location: Sacramento, CA
Posts: 1,710 bricker42 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 38 sec
Reputation Power: 8
Send a message via AIM to bricker42
If you're gonna go the regex way you can make your code a lot shorter. The regex functions will let you search for '<tag>(DATA)</tag>' and return an array of all the matches.

If you want to do it the manual way at the end of your GetElementByName function check $tag to see if it starts with '<![CDATA[' and if it does do another substring to remove the extra information from the front and back of the string.

Alternately if you know the data is going to be wrapped in CDATA tags you could call your function like GetElementByName( $xml, '<job><![CDATA[', ']]></job>' );

Reply With Quote
  #3  
Old February 12th, 2004, 01:35 PM
syncedit syncedit is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 2 syncedit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thx!

works great

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > xml, php


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT