Solved

SimpleXML Query

Posted on 2014-10-24
1
93 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
get domain with php 7 19
Session timeout 5 13
is this a cms? 8 34
PHP get array item with custom id 4 22
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

910 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

19 Experts available now in Live!

Get 1:1 Help Now