xml parsing in php

Discussion in 'PHP' started by phpnewb, Mar 11, 2010.

  1. #1
    I am trying to parse the following xml feed but cannot figure out how to retreive it? Any Ideas? Once I have the data the rest I can do , but for the life of me I cannot find any info on XML Catalog Requests


    To download the catalog, you must form an XML CatalogRequest and send it to your cobranded site's XML URL. This URL can be found on the 'Site Setup' tab under the 'General' sub tab. The XML URL will look similar to the following URL:

    http://p7d6.arixmedia.com/xxxxxxxxxxxxxxxx/xml

    Where 'xxxxxxxxxxxxxxxx' is the cobranded site's numeric ID. The specification for CatalogRequest is documented in the next section in Table 1: CatalogRequest Specification. Below is a sample CatalogRequest:

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <CatalogRequest xml:lang="en-US">
    <XMLPassword>myxmlpassword</XMLPassword>
    <LastUpdated>2005-09-21 06:00:00</LastUpdated>
    </CatalogRequest>

    In the above example our XML password is 'myxmlpassword'. We also only want items that have been added or updated since 6:00am on 9/21/2005.

    Once the CatalogRequest has been sent to the server, it should respond with a CatalogResponse, which contains the actual catalog data. The specification for CatalogResponse is documented in the next section in Table 2: CatalogResponse Specification. Below is a sample CatalogResponse:

    <CatalogResponse>
    <CatalogInfo>
    <LastUpdated format="yyyy-mm-dd hh:mm:ss">2005-09-22 01:13:11</LastUpdated>
    <UrlJs>http://my.4templates.com/8025379375957559/js</UrlJs>
    <CurrList>USD</CurrList>
    </CatalogInfo>
    <Catalog>
    <Item ID="VA0200OR">
    <Description></Description>
    <Type>1</Type>
    <SubType>1</SubType>
    <DateAdded format="yyyy-mm-dd hh:mm:ss">2005-09-22 01:13:11</DateAdded>
    <DateChanged format="yyyy-mm-dd hh:mm:ss">2005-09-22 01:13:11</DateChanged>
    <NumLayouts>3</NumLayouts>
    <ThumbWidth>150</ThumbWidth>
    <ThumbHeight>158</ThumbHeight>
    <Themes>7</Themes>
    <Styles>3,6</Styles>
    <Features>6</Features>
    <Resolution>2</Resolution>
    <Price ID="USD">28.99</Price>
    <Layouts>
    <Layout ID="1">
    <Title>Home Page</Title>
    <UrlThumbnail>http://images.p7d6.arixmedia.com/tn/VA0200OR.gif</UrlThumbnail>
    <UrlPreview>http://images.p7d6.arixmedia.com/pr/VA0200OR.jpg</UrlPreview>
    </Layout>
    <Layout ID="2">
    <Title>Subpage</Title>
    <UrlThumbnail>http://images.p7d6.arixmedia.com/tn/VA0200OR_2.gif</UrlThumbnail>
    <UrlPreview>http://images.p7d6.arixmedia.com/pr/VA0200OR_2.jpg</UrlPreview>
    </Layout>
    <Layout ID="3">
    <Title>Subpage</Title>
    <UrlThumbnail>http://images.p7d6.arixmedia.com/tn/VA0200OR_3.gif</UrlThumbnail>
    <UrlPreview>http://images.p7d6.arixmedia.com/pr/VA0200OR_3.jpg</UrlPreview>
    </Layout>
    </Layouts>
    <JsLinks>
    <UrlCart>javascript: am_cart_add('VA0200OR');</UrlCart>
    <UrlBuy>javascript: am_buy('VA0200OR');</UrlBuy>
    <UrlPreview>javascript: ow_preview_full('VA0200OR');</UrlPreview>
    </JsLinks>
    </Item>
    <Item ID="VA0202BL">
    <Description></Description>
    <Type>1</Type>
    <SubType>1</SubType>
    <DateAdded format="yyyy-mm-dd hh:mm:ss">2005-09-22 01:08:05</DateAdded>
    <DateChanged format="yyyy-mm-dd hh:mm:ss">2005-09-22 01:08:05</DateChanged>
    <NumLayouts>2</NumLayouts>
    <ThumbWidth>150</ThumbWidth>
    <ThumbHeight>154</ThumbHeight>
    <Themes>8</Themes>
    <Styles>3</Styles>
    <Features>6</Features>
    <Resolution>2</Resolution>
    <Price ID="USD">27.99</Price>
    <Layouts>
    <Layout ID="1">
    <Title>Home Page</Title>
    <UrlThumbnail>http://images.p7d6.arixmedia.com/tn/VA0202BL.gif</UrlThumbnail>
    <UrlPreview>http://images.p7d6.arixmedia.com/pr/VA0202BL.jpg</UrlPreview>
    </Layout>
    <Layout ID="2">
    <Title>Subpage</Title>

    <UrlThumbnail>http://images.p7d6.arixmedia.com/tn/VA0202BL_2.gif</UrlThumbnail>
    <UrlPreview>http://images.p7d6.arixmedia.com/pr/VA0202BL_2.jpg</UrlPreview>
    </Layout>
    </Layouts>
    <JsLinks>
    <UrlCart>javascript: am_cart_add('VA0202BL');</UrlCart>
    <UrlBuy>javascript: am_buy('VA0202BL');</UrlBuy>
    <UrlPreview>javascript: ow_preview_full('VA0202BL');</UrlPreview>
    </JsLinks>
    </Item>
    </Catalog>
    </CatalogResponse>

    The above example contains data for only two items. Your initial CatalogResponse will contains thousands.

    Note: When sending your CatalogRequest to the XML URL, make sure you use a method that provides a valid User Agent string. If you are using CURL/PHP, you can use the following code to do this:

    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");

    where $ch is your CURL session handle.
     
    phpnewb, Mar 11, 2010 IP
  2. maryjoanna

    maryjoanna Peon

    Messages:
    287
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you should use simplexml2array command...all the contents of the xml will be stored in an array, just google it for more info
     
    maryjoanna, Mar 11, 2010 IP
  3. phpnewb

    phpnewb Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    but how do i send the password when calling the xml file
     
    phpnewb, Mar 11, 2010 IP
  4. zannovski

    zannovski Greenhorn

    Messages:
    18
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #4
    What you need is to use curl and pass a POST parameter. There are many examples on the web. here is one of them:
    < ?php
    //bot.php
    $url = "http://localhost/wtf/target.php";
    $ch = curl_init();
    
    // set the target url
    curl_setopt($ch, CURLOPT_URL,$url);
    
    // howmany parameter to post
    curl_setopt($ch, CURLOPT_POST, 1);
    
    // the parameter with the Request-XML + password
    $request_xml = '<?xml version="1.0" encoding="ISO-8859-1"?>
    <CatalogRequest xml:lang="en-US">
    <XMLPassword>myxmlpassword</XMLPassword>
    <LastUpdated>2005-09-21 06:00:00</LastUpdated>
    </CatalogRequest>'; 
    curl_setopt($ch, CURLOPT_POSTFIELDS,$request_xml);
    
    $result= curl_exec ($ch);
    curl_close ($ch);
    print $result;
    
    ?>
    
    PHP:
     
    zannovski, Mar 11, 2010 IP