Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-12-16
2
Medium Priority
?
261 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 2000 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

660 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