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

x
?
Solved

SimpleXML Query

Posted on 2014-10-24
1
Medium Priority
?
105 Views
Last Modified: 2014-10-24
Hi,

I am using SimpleXML to take the data from the sample XML below.

How do I extract the Value of CL 1266 by specifically search against Nummer="5"

<WinsApp>
  <Import>
    <ManipulationCtx>
      <Akt>
        <AktPr>
          <AktDaten>
            <AktChiffre Nummer="3">Technisch</AktChiffre>

            <AktChiffre Nummer="5">CL 1266</AktChiffre>

            <AktChiffre Nummer="9">FRA (FRANKFURT MAIN - FRANKFURT)</AktChiffre>
            <AktChiffre Nummer="10">GRZ (GRAZ  - GRAZ)</AktChiffre>
            <AktChiffre Nummer="4">20.05.2012</AktChiffre>
            <AktChiffre Nummer="11">22:10:00</AktChiffre>
            <AktChiffre Nummer="12">20.05.2012</AktChiffre>
            <AktChiffre Nummer="13">23:25:00</AktChiffre>
            <AktChiffre Nummer="28">O</AktChiffre>
          </AktDaten>
        <AktPr>
      <Akt>
    <ManipulationCtx>
  <Import>
<WinsApp>

Thanks

James
0
Comment
Question by:booneball
[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
1 Comment
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 40402316
$xml = <<<XML
<?xml version='1.0'?>
 <WinsApp>
   <Import>
     <ManipulationCtx>
       <Akt>
         <AktPr>
           <AktDaten>
             <AktChiffre Nummer="3">Technisch</AktChiffre>

             <AktChiffre Nummer="5">CL 1266</AktChiffre>

             <AktChiffre Nummer="9">FRA (FRANKFURT MAIN - FRANKFURT)</AktChiffre>
             <AktChiffre Nummer="10">GRZ (GRAZ  - GRAZ)</AktChiffre>
             <AktChiffre Nummer="4">20.05.2012</AktChiffre>
             <AktChiffre Nummer="11">22:10:00</AktChiffre>
             <AktChiffre Nummer="12">20.05.2012</AktChiffre>
             <AktChiffre Nummer="13">23:25:00</AktChiffre>
             <AktChiffre Nummer="28">O</AktChiffre>
           </AktDaten>
         </AktPr>
       </Akt>
     </ManipulationCtx>
   </Import>
 </WinsApp>
XML;

$xml = new SimpleXMLElement($xml);

$p = $xml->xpath('//AktChiffre[@Nummer="3"]');
echo $p[0];

Open in new window

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.

721 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