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
Solved

SimpleXML Query

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Title # Comments Views Activity
What does != "" mean in programming 8 78
PHP Query return divisible by 3 3 26
Currency in SQL? 2 30
Moving from Mcrypt to OpenSSL 18 45
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…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
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 …

856 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