Solved

SimpleXML Query

Posted on 2014-10-24
1
90 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
1 Comment
 
LVL 58

Accepted Solution

by:
Gary earned 500 total points
Comment Utility
$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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
spacing 5 25
MYSQL simple update statement 3 32
compressing images after upload 4 28
Instering to MySQL table 5 15
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 count occurrences of each item in an array.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now