troubleshooting Question

help - php search XML

Avatar of AussieSilver
AussieSilver asked on
PHPXML
8 Comments1 Solution295 ViewsLast Modified:
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>
DML-output.jpg
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 8 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 8 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros