Results 1 to 4 of 4

Thread: Changing DOM code so it works with PHP5

  1. #1
    Join Date
    May 2008
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Changing DOM code so it works with PHP5

    Hi, can anyone show me the best way to make this code compatible with DOM in PHP5. The error seems to stem from domxml_xmltree. It worked with PHP4, and i've been trying (with no success) to get it working with PHP5. I even tried a compatiblity wrapper which did nothing. Cheers

    Code:
    <?
    $file = $_SERVER["DOCUMENT_ROOT"]."/include/regex.xml";
    if (!($fp = fopen($file, "r")))
    {
       die("could not open XML input");
    }
    $data = fread($fp, filesize($file));
    fclose($fp);
    
    $aXMLParams = array();
    
    $oTmp = domxml_xmltree($data);
    
    $aSections = $oTmp->children[0]->children;
    
    
    foreach ($aSections as $k=>$v)
    {
    	if($v->type == 1)
    	{
    		$aXMLParams[$v->attributes[0]->value] = array();
    		$aItems = $v->children;
    		foreach ($aItems as $kk=>$vv)
    		{
    			if($vv->type == 1)
    			{
    				$aItemProps = $vv->children;
    				foreach ($aItemProps as $kkk=>$vvv)
    				{
    					if($vvv->type == 1)
    					{
    						if ($vvv->tagname == "name")
    						{
    							$name = $vvv->children[0]->content;
    						}
    						else
    						{
    							$aNewItemProps[$vvv->tagname] = $vvv->children[0]->content;
    						}
    					}
    				}
    				$aXMLParams[$v->attributes[0]->value][$name] = $aNewItemProps;
    			}
    		}
    	}
    }
    ?>

  2. #2
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    You've got two options.

    Convert to DOM http://www.php.net/manual/en/book.dom.php

    Convert to SimpleXML http://www.php.net/manual/en/book.simplexml.php

    domxml_xmltree does not exist in PHP5.

    I'll try to work out some code examples base on your code. Hopefully that will get you started.

    J

  3. #3
    Join Date
    Apr 2008
    Location
    Limoges, France
    Posts
    395
    Thanks
    13
    Thanked 61 Times in 61 Posts

    Default

    Post an example of regex.xml if you can.

    It is hard for me to understand what is going on in your code after you've got the $aSections variable. Hopefully the code below will at least get you started.

    PHP Code:
    $file $_SERVER["DOCUMENT_ROOT"]."/include/regex.xml";

    $xml file_exists($file) ? simplexml_load_file($file) : false;

    if ( 
    $xml ) {

        
    $aSections $xml->children();

    } else {
        
    // NO XML

    Last edited by JasonDFR; 04-01-2009 at 06:54 AM.

  4. #4
    Join Date
    May 2008
    Posts
    6
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the help Jason, i'll give that a shot as soon as I get home. I'm a bit of a PHP newbie and had this system programmed for me years ago. It's been sitting around ever since. Here's a snippet of the regex file:

    Code:
    <section name="FetchUserInfo">
      <item>
        <name>
          <![CDATA[UpdateId&Nick]]>
        </name>
        <comment>
          <![CDATA[UpdateId&Nick
            
            Update TradeMe id & nick
            match groups:
            1 - user ID
            2 - user nickname]]>
        </comment>
        <url>
          <![CDATA[http://www.trademe.co.nz/MyTradeMe/Default.aspx]]>
        </url>
        <regex>
          <![CDATA[/Listings\.aspx\?member=(\d+).*?<b>([^<>]+)<\/b>/i]]>
        </regex>
      </item>
      <item>
        <name>
          <![CDATA[GetFavCategoriesList]]>
        </name>
        <comment>
          <![CDATA[GetFavCategoriesList
            
            Get user's favourite categories list
            match groups:
            1 - category ID]]>
        </comment>
        <url>
          <![CDATA[http://www.trademe.co.nz/MyTradeMe/Favourites.aspx?pv=2]]>
        </url>
        <regex>
          <![CDATA[/href="\/Browse\/CategoryListings.aspx\?mcat=([\d-]+)&amp;tempregid=\d+"/i]]>
        </regex>
      </item>
      <item>
        <name>
          <![CDATA[GetFavUsersList]]>
        </name>
        <comment>
          <![CDATA[GetFavUsersList
            
            Get user's favourite users list
            match groups:
            1 - favorite user ID]]>
        </comment>
        <url>
          <![CDATA[http://www.trademe.co.nz/MyTradeMe/Favourites.aspx?pv=3]]>
        </url>
        <regex>
          <![CDATA[/href="\/Members\/Listings.aspx\?member=([\d]+)"/i]]>
        </regex>
      </item>
    </section>

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
  •