Solved

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

Posted on 2013-12-16
2
251 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

734 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