XML Parsing code help please!

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
Jester
Forum Newbie
Posts: 2
Joined: Sat Aug 18, 2007 7:11 am

XML Parsing code help please!

Post by Jester »

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]


Hi guys,

I'm trying to write a PHP script which will parse the following XML:

[syntax="xml"]<MyBook>
     <ArticleName>
            <Heading>Article 1</Heading>
            <Quote1>Some text</Quote1>
            <Quote2>Some other text</Quote2>
            <Quote3>Even more text</Quote3>
            <Article>Blah blah blah blah blah blah blah blah blah</Article>
            <Comment1>A comment goes here</Comment>
            <Comment2>Another comment here</Comment2>
      </ArticleName>
      <ArticleName>
            <Heading>Article2</Heading>
blah blah blah to Article 80 or so
</MyBook>
I know just enough PHP to be able to format the output as I would like, but I have never used XML before, and I can't seem to get any examples I have found so far to work.

My goal is to be able to call http://www.mysite.com/articleget.php?article=MyArticle1 or similar and have it return the correct article in the XML database that matches the Heading tag.

Can anyone please help? I tried reading all the documentation and I'm just getting more and more confused!


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]
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

Exaclty which part in the documentation made you feel confused? Show us the code you've tried already (and what your reasoning is behind that code).. this way we can really help you...
thewebdrivers
Forum Commoner
Posts: 41
Joined: Fri Aug 17, 2007 3:32 pm
Location: india
Contact:

Post by thewebdrivers »

Check this out. probably it will help. http://www.wirelessdevnet.com/channels/ ... t_php.html
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: XML Parsing code help please!

Post by superdezign »

Jester wrote:but I have never used XML before, and I can't seem to get any examples I have found so far to work.
XML is just HTML without predefined tags (or, more accurately, HTML is XML with predefined tags). There are standards for RSS, but XML in itself is just tags. Not much you need to understand.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Agreed, pure XML is just a siple document format. But learning everything that goes with it (DTD, XPath, XSL, DOM, SAX) is where experience comes in. I love XML for storing configuration information... it's easy to write, easy to relate one element of data to another, easy to read and easy to parse.

~Jester, look into XPath:

http://www.w3schools.com/xpath/

Then have a play with the DOM XML functions:

http://uk2.php.net/manual/en/ref.domxml.php

Maybe: http://uk2.php.net/manual/en/function.xpath-eval.php

Read the user comments on that last page I linked to.
Jester
Forum Newbie
Posts: 2
Joined: Sat Aug 18, 2007 7:11 am

Post by Jester »

Thanks for your help guys! I'll check into this when I have a bit more time.

Mods - sorry about my code posting! It won't happen again :)
Post Reply