PHP에서 스마트폰과 연동되어 작업될 부분중에 가장 많이 사용할것이 XML이라 XML파싱하는 함수를 뽑아봤습니다.
아래 내용 참고하셔서 올리시면 될것같습니다.
PHP 에서 XML 데이타 파싱하는 클래스입니다.
몇가지 업그레이드 될 여지는 있는 함수이지만 일반적으로 사용하기엔 별무리없이 사용가능합니다.
| /////////////////////////////////////////// ///-- XML 파싱 클래스 사용방법 --/// ////////////////////////////////////////// //XMLParser를 생성합니다. $parser = new XmlParser('http://www.newjinbo.org/xe/rss'); //파싱된 데이타에서 필요한 노드를 뽑아옵니다. $items = $parser->getData('RSS/CHANNEL/ITEM'); //뽑아온 노드를 루프를 돌리면서 최종노드의 값을 받아서 처리합니다. foreach($items as $item){ echo "".$item['TITLE']," "; } ?> //----- XML 파싱 클래스 ---// class XmlParser { public $parser; public $depth=0; public $termStack; public $nodeData; public $fullParseData; public $prevdepth; public $uri; public $last_node; public $inside_data; function XmlParser($uri) { $this->setURI($uri); $this->run(); } function run() { $this->termStack = array(); $this->xmlInit(); $this->parsing(); } function setURI($uri) { $this->uri = $uri; } function xmlInit() { $this->parser = xml_parser_create(); if(!$this->parser) echo "Parser Error "; if(!xml_set_object($this->parser, $this)) echo "xml set object error "; if(!xml_set_element_handler($this->parser, "tag_open", "tag_close")) echo "handler set error "; if(!xml_set_character_data_handler($this->parser, "cdata")) echo "cdata handler error "; } function cdata($parser, $cdata) { if($this->depth > $this->prevdepth) { if($this->inside_data) $this->nodeData[$this->nodeName()] .= $cdata; else $this->nodeData[$this->nodeName()] = $cdata; $this->last_node = $this->nodeName(); } $this->inside_data=true; } function getData($node=null) function parsing() function pushStack($name)
function tag_open($parser, $tag, $attributes) function tag_close($parser, $tag) function nodeName() } ?> |
'아이폰 개발 이야기' 카테고리의 다른 글
| 아이폰 개발하려면 일단 요것부터-2편 (Hellow World) (2) | 2010/05/03 |
|---|---|
| 아이폰 하단 navigationController의 Toolbar에 이미지 버튼 넣는 방법 (0) | 2010/04/27 |
| 아이폰 개발하려면 일단 요것부터-1편 (13) | 2010/04/27 |
| 아이폰 Alert함수 사용법 (0) | 2010/04/22 |
| PHP와 스마트폰의 연동에 있어 XML파싱 (1) | 2010/04/16 |
| iphone 기획 balsamiq으로 쉽고 빠르게.. (0) | 2010/04/13 |



