Link to home
Start Free TrialLog in
Avatar of AussieSilver
AussieSilver

asked on

help - php search XML

I have the following code developed but not complete as I'm quite beginner for PHP. the code prints the results as shown in the image when the user writes for example Brookside which is an element of <series>. Can someone help me to complete the code to result as in the image ?

Cheers,
Php Code:

<?php 
$dom= new DOMDocument;
$dom->load (TVGuide.xml);
$targets=$argv[1];
$seriesList=$dom->getElementByTagName('series')
foreach $seriesList as $series
{
if ($series == $targets)
 echo series->parentnode "\n"
else
{
echo your results are not found;
}




}



XML source file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<TVGuide start="2001-07-05" end="2001-07-05">
  <Channel>
    <Name>BBC1</Name>
    <Program>
      <Start>2001-07-05T19:00:00</Start>
      <Duration>PT30M</Duration>
      <Series>QuestionOfSport</Series>
      <Title></Title>
    </Program>
    <Program rating="5" flag="favorite">
      <Start>2001-07-05T19:30:00</Start>
      <Duration>PT30M</Duration>
      <Series>EastEnders</Series>
      <Title></Title>
      <Description>
        Mark's health scare forces him to reconsider his future with Lisa,
        while Jamie is torn between Sonia and Zoe.
      </Description>
      <CastList>
        <CastMember>
          <Character><Name>Zoe Slater</Name></Character>
          <Actor><Name>Michelle Ryan</Name></Actor>
        </CastMember>
        <CastMember>
          <Character><Name>Jamie Mitchell</Name></Character>
          <Actor><Name>Jack Ryder</Name></Actor>
        </CastMember>
        <CastMember>
          <Character><Name>Sonia Jackson</Name></Character>
          <Actor><Name>Natalie Cassidy</Name></Actor>
        </CastMember>
      </CastList>
      <Writers>
        <Writer><Name>Nick Saltrese</Name></Writer>
        <Writer><Name>Julie Wassmer</Name></Writer>
      </Writers>
      <Director><Name>Stewart Edwards</Name></Director>
      <Producer><Name>Emma Turner</Name></Producer>
    </Program>
    <Program type="documentary">
      <Start>2001-07-05T20:00:00</Start>
      <Duration>PT45M</Duration>
      <Series></Series>
      <Title>Get Real with Casualty</Title>
    </Program>
    <Program>
      <Start>2001-07-05T20:45:00</Start>
      <Duration>PT45M</Duration>
      <Series>Lottery</Series>
      <Title></Title>
    </Program>
    <Program>
      <Start>2001-07-05T21:00:00</Start>
      <Duration>PT1H</Duration>
      <Series>Panorama</Series>
      <Title></Title>
    </Program>
    <Program>
      <Start>2001-07-05T22:00:00</Start>
      <Duration>PT45M</Duration>
      <Series>Lottery</Series>
      <Title></Title>
    </Program>
  </Channel>
  <Channel>
    <Name>BBC2</Name>
    <Program>
      <Start>2001-07-05T19:00:00</Start>
      <Duration>PT1H</Duration>
      <Series>Snooker</Series>
      <Title></Title>
    </Program>
    <Program>
      <Start>2001-07-05T20:00:00</Start>
      <Duration>PT1H</Duration>
      <Series>HomeFront</Series>
      <Title></Title>
    </Program>
    <Program>
      <Start>2001-07-05T21:00:00</Start>
      <Duration>PT50M</Duration>
      <Series>WildAfrica</Series>
      <Title></Title>
    </Program>
    <Program flag="interesting">
      <Start>2001-07-05T21:50:00</Start>
      <Duration>PT40M</Duration>
      <Series>Taboo</Series>
      <Title>Nakedness</Title>
    </Program>
    <Program>
      <Start>2001-07-05T22:30:00</Start>
      <Duration>PT45M</Duration>
      <Series>Lottery</Series>
      <Title></Title>
    </Program>
  </Channel>
  <Channel>
    <Name>ITV</Name>
    <Program>
      <Start>2001-07-05T19:00:00</Start>
      <Duration>PT30M</Duration>
      <Series>Emmerdale</Series>
      <Title></Title>
    </Program>
    <Program>
      <Start>2001-07-05T19:30:00</Start>
      <Duration>PT30M</Duration>
      <Series>CoronationStreet</Series>
      <Title></Title>
    </Program>
    <Program>
      <Start>2001-07-05T20:00:00</Start>
      <Duration>PT1H</Duration>
      <Series>Millionaire</Series>
      <Title></Title>
    </Program>
    <Program type="drama">
      <Start>2001-07-05T21:00:00</Start>
      <Duration>PT2H</Duration>
      <Series></Series>
      <Title>Hot Money</Title>
    </Program>
  </Channel>
  <Channel>
    <Name>Channel 4</Name>
    <Program>
      <Start>2001-07-05T19:00:00</Start>
      <Duration>PT55M</Duration>
      <Series>Channel4News</Series>
      <Title></Title>
    </Program>
    <Program>
      <Start>2001-07-05T19:55:00</Start>
      <Duration>PT5M</Duration>
      <Series>SlotArt</Series>
      <Title></Title>
    </Program>
    <Program>
      <Start>2001-07-05T20:00:00</Start>
      <Duration>PT30M</Duration>
      <Series>Brookside</Series>
      <Title></Title>
    </Program>
    <Program>
      <Start>2001-07-05T20:30:00</Start>
      <Duration>PT30M</Duration>
      <Series>Brookside</Series>
      <Title></Title>
    </Program>
    <Program>
      <Start>2001-07-05T21:00:00</Start>
      <Duration>PT1H</Duration>
      <Series>Swallow</Series>
      <Title></Title>
    </Program>
    <Program flag="favorite">
      <Start>2001-07-05T22:00:00</Start>
      <Duration>PT1H</Duration>
      <Series>AllyMcBeal</Series>
      <Title></Title>
    </Program>
  </Channel>
  <Channel>
    <Name>Channel 5</Name>
    <Program>
      <Start>2001-07-05T19:00:00</Start>
      <Duration>PT30M</Duration>
      <Series>MovieChartShow</Series>
      <Title></Title>
    </Program>
    <Program>
      <Start>2001-07-05T19:30:00</Start>
      <Duration>PT30M</Duration>
      <Series>5News</Series>
      <Title></Title>
    </Program>
    <Program type="entertainment">
      <Start>2001-07-05T20:00:00</Start>
      <Duration>PT1H</Duration>
      <Series></Series>
      <Title>The World's Worst Drivers Caught On Tape</Title>
    </Program>
    <Program type="film">
      <Start>2001-07-05T21:00:00</Start>
      <Duration>PT1H55M</Duration>
      <Series></Series>
      <Title>Black and White</Title>
    </Program>
    <Program>
      <Start>2001-07-05T21:55:00</Start>
      <Duration>PT30M</Duration>
      <Series>Brookside</Series>
      <Title></Title>
    </Program>
  </Channel>
</TVGuide>

Open in new window

DML-output.jpg
Avatar of Amar Bardoliwala
Amar Bardoliwala
Flag of India image

Hello AussieSilver,

I think you can use xpath.

see the following link for help.

http://devzone.zend.com/node/view/id/1713#Heading9

Thanks.
Avatar of AussieSilver
AussieSilver

ASKER

Can you help me developing the code ? I'm stock to complete...
ASKER CERTIFIED SOLUTION
Avatar of hexer4u
hexer4u
Flag of Romania image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hello
I'm stock to complete the code . Would be appreciated if u can complete it
complete code is attached as zip file
xml.zip
Let me recommend a good book for you.  It will help you get from beginner to experienced.
http://www.sitepoint.com/books/phpmysql4/

Buy it right now, and work through the examples.  It even comes with a downloadable code library that you can copy and modify as you test.  A part of my professional library since Version One.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
answered