Solved

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

Posted on 2013-12-16
2
255 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
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 create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

615 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