Solved

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

Posted on 2013-12-16
2
232 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 Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now