[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Muti dimensional array search in xml parser

Posted on 2006-07-19
3
Medium Priority
?
172 Views
Last Modified: 2008-03-06
Hai,
I got xml parser to read xml file the output is like multi dimensional array ,i want to search particular id and get that matched id details from that array if the element have child to read child array also
I give one example here

<map>
<page id="home" name="Home" content="home.xml" template="home.php" bar="home_bar.xml"/>
<page id="training" name="Training" content="training.xml" template="text.php" bar="training_bar.xml">
      <page id="training-trainings" name="Trainings" content="training-trainings.xml" template="text.php" bar="training_bar.xml"/>
      <page id="training-workshops" name="Workshops" content="training-workshops.xml" template="text.php" bar="training_bar.xml"/>
</page>
</map>

If i give search id ="training"
The out put is the values in
 id="training"
 name="Training"
 content="training.xml"
 template="text.php"
 bar="training_bar.xml"

2.If i give search id ="home"
The out put is the values in
 id="home"
 name="Home"
 content="home.xml"
template="home.php"
 bar="home_bar.xml"

and child nodes values are need
 id="training"
 name="Training"
 content="training.xml"
 template="text.php"
 bar="training_bar.xml"

2nd child
 id="training-trainings"
 name="Trainings"
 content="training-trainings.xml"
 template="text.php"
 bar="training_bar.xml"
      <page id="training-workshops" name="Workshops" content="training-workshops.xml" template="text.php" bar="training_bar.xml"/>

My Xml parser out put is like this
Array
(
    [map] => Array
        (
            [page] => Array
                (
                    [0] => Array
                        (
                            [id] => home
                            [name] => Home
                            [content] => home.xml
                            [template] => home.php
                            [bar] => home_bar.xml
                            [value] =>
                        )

                    [1] => Array
                        (
                            [page] => Array
                                (
                                    [0] => Array
                                        (
                                            [id] => training-trainings
                                            [name] => Trainings
                                            [content] => training-trainings.xml
                                            [template] => text.php
                                            [bar] => training_bar.xml
                                            [value] =>
                                        )

                                    [1] => Array
                                        (
                                            [id] => training-workshops
                                            [name] => Workshops
                                            [content] => training-workshops.xml
                                            [template] => text.php
                                            [bar] => training_bar.xml
                                            [value] =>
                                        )

                                )

                            [id] => training
                            [name] => Training
                            [content] => training.xml
                            [template] => text.php
                            [bar] => training_bar.xml
                            [value] =>
                        )

                )

            [value] =>
        )

)



Any Expert help me

Thanks
Bala
0
Comment
Question by:gstalin
[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
3 Comments
 
LVL 49

Accepted Solution

by:
Roonaan earned 2000 total points
ID: 17164214
Lets say the array is stored in $xmlArray, then you should be able to use:

function search($xmlArray, $searchID) {
  foreach($xmlArray['map']['page'] as $key => $pageInfo) {
    if($pageInfo['id'] == $searchID) {
        return $pageInfo;
    }
  }
  return false;
}

Then call it like:

$result = search($xmlArray, 'home');

I hope this helps,

-r-
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses four methods for overlaying images in a container on a web page
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…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

649 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