Jump to content

php xml not a standard format.


monkeytooth

Recommended Posts

The raw output is this..

full example: http://instant.simplyhired.com/a/jobs/xml-v1/l-06238/q-engineer/ws-100/si-0/fdb-21/sb-rd/mi-10

I can generally get the value of this stuff.. like if I wanted the "jt" line I can get ENGINEER, and the rest of the data.. what i am having trouble with is getting the attribute (i think thats the right term for this with XML). For example the "src" line it as an attribute "url=" I am trying to figure out how to get that value.. Below is a sample of the raw.. and below that is the code I am working with to load up the XML. I know theres simple_xml but in my case thats not an option so I am working on slightly custom work (as little as it is).

 

<r>
  <jt>ENGINEER</jt>
  <cn url="">Soldream</cn>
  <src url="http://instant.simplyhired.com/a/job-details/view/jobkey-5109.J3H3036RVZPZ4RFRRKR/jp-0/hits-70?aff_id=2512">CareerBuilder</src>
  <loc cty="Tolland" st="CT" postal="06084" county="" region="" country="US">Tolland, CT</loc>
  <ls>2011-02-20T13:28:39Z</ls>
  <dp>2011-02-18T08:00:00Z</dp>
  <e>Engineer/CNC Machinist Tolland CT2429177 Aerospace MFG Co. seeks MFG/Design Engineer &amp; CNC Machinist with 5+ years of experience in aerospace manufacturing. Duties for engineers include developing new processes, drafting, and CNC programming. CNC Machinist should have knowledge of FANUC control. Send resume to...</e>
  <af></af>

  <pl url=""/>
</r>

 

 

$feedURL = 'http://instant.simplyhired.com/a/jobs/xml-v1/l-06238/q-engineer/ws-100/si-0/fdb-21/sb-rd/mi-10';
$doc = new DOMDocument();
$doc->load($feedURL);
$arrFeeds = array();
foreach ($doc->getElementsByTagName('r') as $node) {
$itemRSS = array ( 
   'title' => $node->getElementsByTagName('jt')->item(0)->nodeValue,
   'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
   'link' => $node->getAttributeNode('src'),
   'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
   'creator' => $node->getElementsByTagName('creator')->item(0)->nodeValue,
   'permaz' => $node->getElementsByTagName('guid')->item(0)->nodeValue
);
array_push($arrFeeds, $itemRSS);
//print_r($arrFeeds);
}
array_unique($arrFeeds);
?>

 

Link to comment
Share on other sites

DOMDocument::GetElementsByTagName() returns a DOMNodeList, and each item is a DOMNode.  A DOMNode has a hasAttributes() method, and an attributes property of type DOMNamedNodeMap.  I would expect the attributes to be in there, and accessible using DOMNamedNodeMap::getNamedItem()

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.