how to parse a xml file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
basudeb
Forum Commoner
Posts: 44
Joined: Wed Dec 20, 2006 12:13 am

how to parse a xml file

Post by basudeb »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I need a xml file to parse . The xml file content is given. Please give the code for that.



[syntax="xml"]<?xml version="1.0" encoding="iso-8859-1"?>
<NewsML>
  <Catalog Href="http://www.afp.com/dtd/AFPCatalog.xml"/>
  <NewsEnvelope>
    <DateAndTime>20060612T202938Z</DateAndTime>
  </NewsEnvelope>
  <NewsItem>
    <Identification>
      <NewsIdentifier>
        <ProviderId>afp.com</ProviderId>
        <DateId>20060612</DateId>
        <NewsItemId>mmd--espanol--periodico--mundial2006-pordentro</NewsItemId>
        <RevisionId PreviousRevision="0" Update="N">1</RevisionId>
        <PublicIdentifier>urn:newsml:afp.com:20060612:mmd--espanol--periodico--mundial2006-pordentro:1</PublicIdentifier>
      </NewsIdentifier>
      <NameLabel>Mundial-2006 por dentro</NameLabel>
    </Identification>
    <NewsManagement>
      <NewsItemType FormalName="News"/>
      <FirstCreated>20060612T202938Z</FirstCreated>
      <ThisRevisionCreated>20060612T202938Z</ThisRevisionCreated>
      <Status FormalName="Usable"/>
    </NewsManagement>
    <NewsComponent>
      <AdministrativeMetadata>
        <Provider>
          <Party FormalName="AFP"/>
        </Provider>
      </AdministrativeMetadata>
      <DescriptiveMetadata>
        <Language FormalName="es"/> 
      </DescriptiveMetadata>
      <NewsComponent>
        <NewsLines>
          <HeadLine>Messi: "estoy recuperado de la lesión y listo para jugar"</HeadLine>
        </NewsLines>
        <NewsItemRef NewsItem="060612172625.b80s0qm6.xml"/>
      </NewsComponent>
      <NewsComponent>
        <NewsLines>
          <HeadLine>Klose y Podolski, dos polacos contra su patria</HeadLine>
        </NewsLines>
        <NewsItemRef NewsItem="060612202930.yrvcf1cj.xml"/>
      </NewsComponent>
      <NewsComponent>
        <NewsLines>
          <HeadLine>Los organizadores creen que pondrán el cartel de "no hay billetes"</HeadLine>
        </NewsLines>
        <NewsItemRef NewsItem="060612140533.xw2i1168.xml"/>
      </NewsComponent>
      <NewsComponent>
        <NewsLines>
          <HeadLine>Maradona dijo que los jugadores argentinos "están muy afilados"</HeadLine>
        </NewsLines>
        <NewsItemRef NewsItem="060612194205.1d49c34m.xml"/>
      </NewsComponent>
      <NewsComponent>
        <NewsLines>
          <HeadLine>El ataque de Inglaterra hace sufrir a Eriksson</HeadLine>
        </NewsLines>
        <NewsItemRef NewsItem="060612134107.lsevuk92.xml"/>
      </NewsComponent>
      <NewsComponent>
        <NewsLines>
          <HeadLine>La hora del chico malo Adebayor</HeadLine>
        </NewsLines>
        <NewsItemRef NewsItem="060612145058.c8p6wd2f.xml"/>
      </NewsComponent>
      <NewsComponent>
        <NewsLines>
          <HeadLine>Van Persie y Robben desmienten sus diferencias</HeadLine>
        </NewsLines>
        <NewsItemRef NewsItem="060612135549.rafxhd5v.xml"/>
      </NewsComponent>
      <NewsComponent>
        <NewsLines>
          <HeadLine>Sangre de las colonias nutre a potencias europeas en el Mundial</HeadLine>
        </NewsLines>
        <NewsItemRef NewsItem="060612200537.nbwvwwiw.xml"/>
      </NewsComponent>
      <NewsComponent>
        <NewsLines>
          <HeadLine>El estadio Olímpico de Berlín: hormigón, vidrio y... símbolo</HeadLine>
        </NewsLines>
        <NewsItemRef NewsItem="060612180735.9hcqo8gs.xml"/>
      </NewsComponent>
      <NewsComponent>
        <NewsLines>
          <HeadLine>Las estrellas del Chelsea brillan en el Mundial</HeadLine>
        </NewsLines>
        <NewsItemRef NewsItem="060612193143.rubphqk7.xml"/>
      </NewsComponent>
    </NewsComponent>
  </NewsItem>
</NewsML>

feyd | Please use[/syntax]

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Give the code. :lol: You're funny. :-p

PHP has a built-in XML Parser. Take a look at it.

There's also libxml, and there's SimpleXML for PHP5.
Post Reply