SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot dizyn's Avatar
    Join Date
    Apr 2006
    Posts
    181
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    regular express issue

    I want to fetch value of msg element using regular expression. Please help

    Code:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <epp xmlns="urn:iana:xml:ns:epp-1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:iana:xml:ns:epp-1.0 epp-1.0.xsd">
        <result code="2400">
          <msg>Command fail</msg>
    	  <value>mjdizyn.com</value>
        </result>
        <unspec/>
    </epp>
    I am using this code:

    PHP Code:
    function startElement($parser$name$attrs)
    {
        if(
    $name == "MSG")
        {
            global 
    $a;
            
    $a 0;
        }
    }
    function 
    endElement($parser$name)
    {
    }
    function 
    characterData($parser$name)
    {
    }
    $xml_parser xml_parser_create();
    xml_set_element_handler($xml_parser"startElement""endElement");
    xml_set_character_data_handler($xml_parser"characterData");
    //$fp = fopen($file, "r");
    $data $file//fread($fp, 4096);
    xml_parse($xml_parser$data);
    xml_parser_free($xml_parser); 

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,788
    Mentioned
    153 Post(s)
    Tagged
    3 Thread(s)
    The regex would be something like:
    PHP Code:

    preg_match
    ("/<msg>(.*?)<\/msg>/"$text$matches); 
    where $text is the data.
    It returns an array of matches:
    Code:
    Array ( [0] => Command fail [1] => Command fail )
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I have no experience using PHP's XML parser, but can't it be used for this exact purpose?

  4. #4
    SitePoint Addict mmanders's Avatar
    Join Date
    Jul 2006
    Location
    Edinburgh, Scotland
    Posts
    358
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am in a similar position as Raffles, so this is just speculation but doesn't the PHP XML parser support XPath experssions that would allow you to target the CDATA contained within any arbitrary element.


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
  •