Esempio n. 1
0
 function test_preserveCase()
 {
     //This file was retrieved from http://www.rssboard.org/files/sample-rss-2.xml
     //	-- Linked from page: http://www.rssboard.org/rss-specification
     $testFile = dirname(__FILE__) . '/files/testPreserveCase.xml';
     $parser = new cs_phpxmlParser(file_get_contents($testFile), true);
     $this->assertEquals('Tue, 10 Jun 2003 04:00:00 GMT', $parser->get_path('/rss/channel/pubDate/' . cs_phpxmlCreator::dataIndex));
     $this->assertEquals($parser->get_path('/rss/channel/pubDate/' . cs_phpxmlCreator::dataIndex), $parser->get_tag_value('/rss/channel/pubDate'));
     $this->assertNotEquals($parser->get_path('/rss/channel/item/0/value/' . cs_phpxmlCreator::dataIndex), $parser->get_path('/rss/channel/item/0/Value/' . cs_phpxmlCreator::dataIndex));
     $this->assertEquals('Testing cs_phpxml1', $parser->get_path('/rss/channel/item/0/value/' . cs_phpxmlCreator::dataIndex));
     $this->assertEquals('Testing cs_phpxml2', $parser->get_path('/rss/channel/item/0/Value/' . cs_phpxmlCreator::dataIndex));
     $this->assertEquals('test 2', $parser->get_attribute('/rss/channel/item/0/Value', 'note'));
     $this->assertEquals('test 1', $parser->get_attribute('/rss/channel/item/0/value', 'note'));
     $xml = new cs_phpxmlCreator('rss', null, true);
     $pathBase = '/rss/channel';
     $xml->add_tag($pathBase);
     $createData = array('title' => "Liftoff News", 'link' => "http://liftoff.msfc.nasa.gov/", 'description' => "Liftoff to Space Exploration.", 'language' => "en-us", 'pubDate' => "Tue, 10 Jun 2003 04:00:00 GMT", 'lastBuildDate' => "Tue, 10 Jun 2003 09:41:01 GMT", 'docs' => "http://blogs.law.harvard.edu/tech/rss", 'generator' => "Weblog Editor 2.0", 'managingEditor' => "*****@*****.**", 'webMaster' => "*****@*****.**");
     foreach ($createData as $tagPart => $tagData) {
         $xml->add_tag($pathBase . '/' . $tagPart, $tagData);
     }
     //build items.
     $itemsData = array(0 => array('title' => "Star City", 'link' => "http://liftoff.msfc.nasa.gov/news/2003/news-starcity.asp", 'description' => "How do Americans get ready to work with Russians aboard the International Space Station? They take a crash course in culture, language and protocol at Russia's <a href=\"http://howe.iki.rssi.ru/GCTC/gctc_e.htm\">Star City</a>.", 'pubDate' => "Tue, 03 Jun 2003 09:39:21 GMT", 'guid' => "http://liftoff.msfc.nasa.gov/2003/06/03.html#item573", 'value' => "Testing cs_phpxml1", 'Value' => "Testing cs_phpxml2"), 1 => array('description' => "Sky watchers in Europe, Asia, and parts of Alaska and Canada will experience a <a href=\"http://science.nasa.gov/headlines/y2003/30may_solareclipse.htm\">partial eclipse of the Sun</a> on Saturday, May 31st.", 'pubDate' => "Fri, 30 May 2003 11:06:42 GMT", 'guid' => "http://liftoff.msfc.nasa.gov/2003/05/30.html#item572"), 2 => array('title' => "The Engine That Does More", 'link' => "http://liftoff.msfc.nasa.gov/news/2003/news-VASIMR.asp", 'description' => "Before man travels to Mars, NASA hopes to design new engines that will let us fly through the Solar System more quickly.  The proposed VASIMR engine would do that.", 'pubDate' => "Tue, 27 May 2003 08:37:32 GMT", 'guid' => "http://liftoff.msfc.nasa.gov/2003/05/27.html#item571"), 3 => array('title' => "Astronaut's Dirty Laundry", 'link' => "http://liftoff.msfc.nasa.gov/news/2003/news-laundry.asp", 'description' => "Compared to earlier spacecraft, the International Space Station has many luxuries, but laundry facilities are not one of them.  Instead, astronauts have other options.", 'pubDate' => "Tue, 20 May 2003 08:56:02 GMT", 'guid' => "http://liftoff.msfc.nasa.gov/2003/05/20.html#item570"));
     foreach ($itemsData as $i => $myTagData) {
         $myPath = $pathBase . '/item/' . $i;
         $xml->add_tag($myPath);
         foreach ($myTagData as $n => $v) {
             $xml->add_tag($myPath . '/' . $n, $v);
         }
     }
     $xml->add_attribute($pathBase . '/item/0/value', array('note' => "test 1"));
     $xml->add_attribute($pathBase . '/item/0/Value', array('note' => "test 2"));
 }
 /**
  * Takes an XMLParser object & loads data from it as the internal XML array. This 
  * facilitates the ability to add data to existing XML.
  */
 public function load_xmlparser_data(cs_phpxmlParser $obj)
 {
     //TODO: need to be able to re-populate $this->tags & $this->attributes
     $data = $obj->get_tree();
     $this->xmlArray = $data;
     $this->a2p = new cs_arrayToPath($data);
     $x = array_keys($this->a2p->get_data(NULL));
     if (count($x) > 1) {
         throw new exception(__METHOD__ . ": too many root elements");
     } else {
         $this->rootElement = $x[0];
     }
 }