xml is externalFile.xml and has xml start tags

I had this question after viewing given xml, please extract a portion of xml line in output one per line.

Thanks. I have a related question where xml is externalFile.xml and has xml start tags
LVL 1
rgb192Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
I find the documentation to be the best source for finding alternate methods.

In this case the code in the previous question used LoadXML.

Start with that doc link:
http://php.net/manual/en/domdocument.loadxml.php

Then way down at the bottom you see:
See Also
•DOMDocument::load() - Load XML from a file


That takes you to:
http://php.net/manual/en/domdocument.load.php
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
By use the DOMDocument's load method as slightwv mentioned, here's an example.

1. let's say you got externalFile.xml with these content:

<smses>
<sms protocol="0" address="5551212" date="1500334066013" type="2" subject="null" body="I ONLY WANT BODY OF MESSAGE 1" toa="null" sc_toa="null" service_center="null" read="1" status="-1" locked="0" date_sent="0" readable_date="Jul 17, 2017 7:27:46 PM" contact_name="(Unknown)" />
 <sms protocol="0" address="5551212" date="1500334066013" type="2" subject="null" body="I ONLY WANT BODY OF MESSAGE 2" toa="null" sc_toa="null" service_center="null" read="1" status="-1" locked="0" date_sent="0" readable_date="Jul 17, 2017 7:27:46 PM" contact_name="(Unknown)" />
 <sms protocol="0" address="5551212" date="1500334066013" type="2" subject="null" body="I ONLY WANT BODY OF MESSAGE 3" toa="null" sc_toa="null" service_center="null" read="1" status="-1" locked="0" date_sent="0" readable_date="Jul 17, 2017 7:27:46 PM" contact_name="(Unknown)" />
 <sms protocol="0" address="5551212" date="1500334066013" type="2" subject="null" body="I ONLY WANT BODY OF MESSAGE 4" toa="null" sc_toa="null" service_center="null" read="1" status="-1" locked="0" date_sent="0" readable_date="Jul 17, 2017 7:27:46 PM" contact_name="(Unknown)" />
 <sms protocol="0" address="5551212" date="1500334066013" type="2" subject="null" body="I ONLY WANT BODY OF MESSAGE 5" toa="null" sc_toa="null" service_center="null" read="1" status="-1" locked="0" date_sent="0" readable_date="Jul 17, 2017 7:27:46 PM" contact_name="(Unknown)" />
 <sms protocol="0" address="5551212" date="1500334066013" type="2" subject="null" body="I ONLY WANT BODY OF MESSAGE 6" toa="null" sc_toa="null" service_center="null" read="1" status="-1" locked="0" date_sent="0" readable_date="Jul 17, 2017 7:27:46 PM" contact_name="(Unknown)" />
</smses>

Open in new window


2. apply codes like this:

<?php

$doc = new DOMDocument();
$file = "D:\\yourPath\\externalFile.xml";
$doc->load($file);

$smses = $doc->getElementsByTagName('sms');
foreach ($smses as $sms) {
    $body = $sms->getAttribute('body');
    echo $body."<br>";
}

?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
do you need further clarification here?

example above should work for you as well.
0
rgb192Author Commented:
this got the body tag

thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.