pulling a single bit of info from an xml
Hi everyone...I'm extremely new to both xml and php and I'm trying to get my bearings here.
I’ve looked at so much information but can’t find a simple script that will let me pull a simple object out of a xml if I already know what the id for that object is. Can someone get me started here? Say I want to pull the name for id 2 from the xml?
If you have a simple xml called friends.xml
<people>
<id>1</id>
<name>Joe</name>
</people>
<people>
<id>2</id>
<name>Mike</name>
</people>
With simplexml I can get to the file by doing
$myfriends = simplexml_load_file(friends.xml);
But I can't find any info on how to pull a single piece of info from an xml.
Having trouble writing back
Still trying to figure this out. So I created a counter and am trying to read then add 1 to counter before replacing orginal number. I can read fine but the writing I've got all messed up.
Can someone tell me what I'm doing wrong here?
XML File named counter.xml
<?xml version="1.0" encoding="utf-8"?>
<counters>
<mycount>
<numcount>1</numcount>
</mycount>
</counters>
I get the count
<?php
//get count
$doc = new DOMDocument();
$doc->load('counter.xml');
$mycount = $doc->getElementsByTagName( "mycount" );
$numcount = $mycount->item(0)->nodeValue;
echo"<input type='text' name='count' id='count' value=$numcount>"
?>
Add 1 and write back...so I don't need an array with just one number but an array can have one number. I wanted to make it so it would work on things that have multiple elements.
<?php
//function called from web page
function newquote()
{
//change counter
$count = document.insertsidebar.count.value + 1;
//writing to counter xml
$mycount = array();
$mycount [] = array('mycount' => $count);
$doc = new DOMDocument();
$doc->formatOutput = true;
$r = $doc->createElement(counters);
$doc->appendChild($r);
foreach ($counters as $mycount)
{
$b = $doc->createElement( "counter" );
$count = $doc->createElement( "count" );
$b->appendChild( "counter" );
$r->appendChild( $b );
}
echo $doc->saveXML();
$doc->save("counter.xml");
}
?>
Need Help in Making XML Dynamic
Below is the code in my slideshow.php which is behaving as XML properly But What want is My music and images should be dynamically fetched from database.How can i do that.
PHP Code:
<?php
file_put_contents('slideshow.xml', '<?xml version="1.0" encoding="iso-8859-1"?>
<slideshow displayTime="5"
transitionSpeed=".7"
transitionType="Fade"
motionType="None"
motionEasing="easeInOut"
randomize="false"
slideshowWidth="400"
slideshowHeight="220"
slideshowX="center"
slideshowY="0"
bgColor="FFFFFF"
bgOpacity="100"
useHtml="true"
showHideCaption="false"
captionBg="000000"
captionBgOpacity="0"
captionTextSize="11"
captionTextColor="FFFFFF"
captionBold="false"
captionPadding="7"
showNav="false"
autoHideNav="false"
navHiddenOpacity="40"
navX="335"
navY="193"
btnColor="FFFFFF"
btnHoverColor="FFCC00"
btnShadowOpacity="85"
btnGradientOpacity="20"
btnScale="120"
btnSpace="7"
navBgColor="333333"
navBgAlpha="0"
navCornerRadius="0"
navBorderWidth="1"
navBorderColor="FFFFFF"
navBorderAlpha="0"
navPadding="8"
tooltipSize="8"
tooltipColor="000000"
tooltipBold="true"
tooltipFill="FFFFFF"
tooltipStrokeColor="000000"
tooltipFillAlpha="80"
tooltipStroke="0"
tooltipStrokeAlpha="0"
tooltipCornerRadius="8"
loaderWidth="200"
loaderHeight="1"
loaderColor="FF0000"
loaderOpacity="100"
attachCaptionToImage="true"
cropImages="false"
slideshowMargin="0"
showMusicButton="false"
music="[COLOR="Red"]upload/1.mp3[/COLOR]"
musicVolume="50"
musicMuted="false"
musicLoop="true"
watermark=""
watermarkX="625"
watermarkY="30"
watermarkOpacity="100"
watermarkLink=""
watermarkLinkTarget="_blank"
captionsY="bottom"
>
<image img="[COLOR="red"]upload/2.jpg[/COLOR]" customtitle="Camomile" />
<image img="[COLOR="Red"]upload/3.jpg[/COLOR]" customtitle="Bells" />
<image img="[COLOR="Red"]upload/4.jpg[/COLOR]" customtitle="Market" />
<image img="[COLOR="Red"]upload/5.jpg[/COLOR]" customtitle="Market" />
</slideshow>', LOCK_EX);
?>