SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SimpleXML Help needed (reading and displaying)

    Hello all, and thanks in advance for reading,

    I have the following XML File:

    Code XML:
    <ruleset>
    	<rule id="10">
    	<name>Campaign 1</name>
    		<match>
    			<keyword>123</keyword>
    			<keyword>car</keyword>
    		</match>
    		<results>
    			<result>
    				<title><![CDATA[Some cutom <b>title</b>]]></title>
    				<body><![CDATA[This is result <b>body</b>! bla bla bla bla bla bla bla bla bla bla]]></body>
    				<visibleurl><![CDATA[www.<b>ukr.net</b>]]></visibleurl>
    				<clickurl>http://www.ukr.net/</clickurl>
    			</result>
    			<result>
    				<title><![CDATA[Second <b>title</b>]]></title>
    				<body><![CDATA[This is second body. Here could be your advertising!]]></body>
    				<visibleurl><![CDATA[www.<b>ukr.net</b>]]></visibleurl>
    				<clickurl>http://www.ukr.net/</clickurl>
    			</result>
    		</results>
    	</rule>
     
    	<rule id="77">
    	<name>Campaign 2</name>
    		<match>
    			<keyword>abc</keyword>
    			<keyword>qwe</keyword>
    		</match>
    		<results>
    			<result>
    				<title><![CDATA[Third title]]></title>
    				<body><![CDATA[A title is a prefix or suffix added to someone's name to signify either veneration, an official position or a professional or academic qualification. <b>...</b>]]></body>
    				<visibleurl><![CDATA[www.<b>ya.net</b>]]></visibleurl>
    				<clickurl>http://www.ya.ru/</clickurl>
    			</result>
    		</results>
    	</rule>
     
    </ruleset>

    And i am looking to read through it. I want to loop through the <rule id=""> trees, and load the data in each of them in an array.

    Sofar i have this:
    Code PHP:
    $filename = $_SERVER['DOCUMENT_ROOT']."/users/".$_SESSION[request::authHash()]['id']."/serp.xml";
    		$handle = fopen($filename,'r+') or die("Cannot open file");
    		$contents = fread($handle, filesize($filename));
    		fclose($handle);
    		$xml = new SimpleXMLElement($contents);
     
     
    		$data = array();
     
    		foreach ($xml->xpath('rule') as $v) {
     
     
     
     
     
    			array_push($data, array(
    				'id' => $v->rule,
    				'name' => $v->name
    			));
    		} 
     
    		$this->tpl->assign('data', $data);
     
    		$this->tpl->display('admin_serp.tpl');
    	}

    Ive got the names being pushed perfectly now, but i want the <rule id=""> to be read and be passed in the id field, how do i do that?



    Regards

  2. #2
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    61 Post(s)
    Tagged
    0 Thread(s)
    Please post your answer so that others can learn from your experience.
    Salathe
    Software Developer and PHP Manual Author.

  3. #3
    SitePoint Member
    Join Date
    May 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i reedited my code, now i got a new problem, whats up there works but doesnt do exactly what i want yet

  4. #4
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    61 Post(s)
    Tagged
    0 Thread(s)
    Would you like any help with it?
    Salathe
    Software Developer and PHP Manual Author.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •