Solved

Trouble loading xml files through email piping - found one issue I need to resolve

Posted on 2013-12-16
2
243 Views
Last Modified: 2013-12-16
Hi,
This has been the bane of my existence:
I receive various emails from auto sell portals. They are all ADF format but not surprisingly, seems no one can stick to the actual format. I'm having an issue parsing this:
<?ADF VERSION="1.0"?>
<?xml version="1.0"?>
<adf>
  <prospect status="new">
    <id sequence="1" source="Strathcom">1122880</id>
    <requestdate>2013-12-16T08:50:05</requestdate>
    <vendor>
      <vendorname>The Jeep Store</vendorname>
    </vendor>
    <provider>
      <service>548756935</service>
      <url>www.kijiji.ca</url>
      <name part="full">Kijiji</name>
    </provider>
    <customer>
      <comments>I am interested in trading my 2007 Chrysler pacifica for this truck is the front seat a bench seat</comments>
      <contact>
        <name part="first">James</name>
        <name part="last">Unknown</name>
        <email>hisemail@hotmail.com</email>
      </contact>
    </customer>
    <vehicle interest="buy" status="used">
      <id sequence="1" source="Strathcom">3582033</id>
      <year>2008</year>
      <make>Dodge</make>
      <model>Dakota</model>
      <stock>P99764A</stock>
      <trim>SXT</trim>
      <odometer>87367</odometer>
      <price>11980</price>
    </vehicle>
  </prospect>
</adf>

Open in new window

What I'm finding is these guys like to put the declarations backwards far as I can tell.

They do:
<?ADF VERSION="1.0"?>
<?xml version="1.0"?>

But everyone else does:
<?xml version="1.0"?>
<?ADF VERSION="1.0"?>

A common denominator is, if I can remove <?ADF VERSION="1.0"?> or even both lines altogether, they'll work as expected. So my question is, "how would I get rid of the ADF line or even both lines?

Thanks as always.
0
Comment
Question by:tjyoung
2 Comments
 
LVL 2

Accepted Solution

by:
ITTallahassee earned 500 total points
ID: 39721826
Without more information (how you are bringing this information in and what kind of variable it is kept in), if you just want to remove every thing before "<adf>" and it is in a string ($str):

$newstr = substr($str, ($pos = strpos($str, '<adf>')) !== false ? $pos - 1 : 0);

When the code below is run - it echos out everything but the top 2 lines.

$str = '<?ADF VERSION="1.0"?>
<?xml version="1.0"?>
<adf>
  <prospect status="new">
    <id sequence="1" source="Strathcom">1122880</id>
    <requestdate>2013-12-16T08:50:05</requestdate>
    <vendor>
      <vendorname>The Jeep Store</vendorname>
    </vendor>
    <provider>
      <service>548756935</service>
      <url>www.kijiji.ca</url>
      <name part="full">Kijiji</name>
    </provider>
    <customer>
      <comments>I am interested in trading my 2007 Chrysler pacifica for this truck is the front seat a bench seat</comments>
      <contact>
        <name part="first">James</name>
        <name part="last">Unknown</name>
        <email>hisemail@hotmail.com</email>
      </contact>
    </customer>
    <vehicle interest="buy" status="used">
      <id sequence="1" source="Strathcom">3582033</id>
      <year>2008</year>
      <make>Dodge</make>
      <model>Dakota</model>
      <stock>P99764A</stock>
      <trim>SXT</trim>
      <odometer>87367</odometer>
      <price>11980</price>
    </vehicle>
  </prospect>
</adf>';

echo $newstr = substr($str, ($pos = strpos($str, '<adf>')) !== false ? $pos -1 : 0);

Open in new window

0
 
LVL 1

Author Closing Comment

by:tjyoung
ID: 39721845
Thank you. That was exactly my scenario. Appreciate you taking the time despite my vagueness.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question