Jump to content
hungryfrank

how do i parse this xml

Recommended Posts

i am getting a syntax error in dreamweaver when i use this code because of blank space. 

$xml = simplexml_load_string($responseXml);

foreach ($xml->Fees as $mes) {
    $name= $mes->fee->name ;
	$fee=$mes->fee->Fee currencyID="USD";
if ($name=='ListingFee')$listingfee=$mes->fee->Fee currencyID="USD";
}

i am trying to get the listingfee from this 

<AddItemResponse xmlns="urn:ebay:apis:eBLBaseComponents">
  <Timestamp>2016-02-16T18:52:41.543Z</Timestamp>
  <Ack>Success</Ack>
  <Version>967</Version>
  <Build>E967_CORE_BUNDLED_10639415_R1</Build>
  <ItemID>110043671232</ItemID>
  <StartTime>2016-02-16T18:52:41.027Z</StartTime>
  <EndTime>2016-02-23T18:52:41.027Z</EndTime>
  <Fees>
    <Fee>
      <Name>AuctionLengthFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>BoldFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>BuyItNowFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>CategoryFeaturedFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>FeaturedFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>GalleryPlusFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>FeaturedGalleryFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>FixedPriceDurationFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>GalleryFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>GiftIconFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>HighLightFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>InsertionFee</Name>
      <Fee currencyID="USD">0.25</Fee>
    </Fee>
    <Fee>
      <Name>InternationalInsertionFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>ListingDesignerFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>ListingFee</Name>
      <Fee currencyID="USD">0.25</Fee>
    </Fee>
    <Fee>
      <Name>PhotoDisplayFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>PhotoFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>ReserveFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>SchedulingFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>SubtitleFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>BorderFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>ProPackBundleFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>BasicUpgradePackBundleFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>ValuePackBundleFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>PrivateListingFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>ExtendedDurationFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>ProPackPlusBundleFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
    <Fee>
      <Name>MotorsGermanySearchFee</Name>
      <Fee currencyID="USD">0.0</Fee>
    </Fee>
  </Fees>
</AddItemResponse>

Share this post


Link to post
Share on other sites

The name of the node is just "Fee". The rest of it is an attribute of the node.

Share this post


Link to post
Share on other sites

Perhaps

$listingFee = '';
foreach ($xml->Fees->Fee as $fee) {
    if ($fee->Name=='ListingFee') {
        $listingFee = sprintf('%0.2f%s', $fee->Fee, $fee->Fee['currencyID']);
    }
}
echo $listingFee;   //--> 0.25USD

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.