Jump to content

searching XML using XMLReader


nadeemshafi9

Recommended Posts

my current function can only output the entire XML document

 

i am having a hard time trying to searhc the titles in the XML and then output node that contains the search arg

 

i need to mod the below to only output if title contains args, i have tried a few ways but have reverted to this full output, ihave tried moving back and forward with no success

 

<?php
final public static function all( $args ){
	$xml = new XMLReader(); 
	$xml->open('music.xml');

	echo "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";

                         // i need to use args to limit the output to  the nodes that contain args in there title

	while ($xml->read()) {
		if($xml->nodeType == XMLREADER::ELEMENT) echo "<".$xml->localName.">";
		echo $xml->value;
		if($xml->nodeType == XMLREADER::END_ELEMENT) echo "</".$xml->localName.">";
	}
	$xml->close();
}
?>

 

 

xml file

 

<?xml version="1.0" encoding="UTF-8" ?>
<music>
<file name="1">
	<title>1</title>
	<filename>1.mp3</filename>
</file>
<file name="2">
	<title>2</title>
	<filename>2.mp3</filename>
</file>
<file name="3">
	<title>3</title>
	<filename>3.mp3</filename>
</file>
<file name="4">
	<title>4</title>
	<filename>4.mp3</filename>
</file>
</music>

 

any help much appreciated

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.