Jump to content

having issue with pull an XML value...


Ash3r

Recommended Posts

I am trying to create a TeamWarfare.com plugin for a clan.

 

I am new to PHP coding so please excuse me for my bad code...

Here is the page that I am using to test my core framework of the plugin i am trying to create ... http://testing.a3designs.com

 

Here is the XML entry...

<ladder name="Battlefield: Bad Company 2 - NA 4v4 Squad Rush">

 

I want to pull the "Battlefield: Bad Company 2 - NA 4v4 Squad Rush" portion of the code.

 

Here is the code I have been using to pull XML info for other fields...

    $name = $value->getElementsByTagName("name"); 
    $names  = $name->item(0)->nodeValue; 	

i have tried using

$ladder =

and

$name =

and

'$ladder name' =

 

but i am stuck on this little tiny issue ... please someone help me !

Link to comment
https://forums.phpfreaks.com/topic/198803-having-issue-with-pull-an-xml-value/
Share on other sites

here is a snipit from the XML document...

 

<competitioninformation>
	<ladder name="Battlefield: Bad Company 2 - NA 4v4 Squad Rush">
		<ladderlink>
			<httplink>http://www.alinkgoeshere.com</httplink>
			<xmllink>http://www.anXMLgoeshere.com</xmllink>
		</ladderlink>
		<rank>2</rank>
		<wins>0</wins>

 

The Battlefield: Bad Company 2 ... etc ... line "value" is what i am trying to pull.

Asher You seem to be using some custom XML DOM Class.

 

When you use getElementsByTagName(), you give it the Tag Name, not just 'name'.

 

This line will then give you the value of the first occurance of that tag. (I Assume, since i dont now your class).

$names  = $name->item(0)->nodeValue; 

 

-- To people wondering what $value is;

It is a class, similar to:

http://uk2.php.net/manual/en/function.domelement-get-elements-by-tagname.php

 

-cb-

 

<?php
$url = 'http://www.teamwarfare.com/xml/viewteam_v2.asp?team=Late+Nite+Commandos';

$xml = simplexml_load_file($url);

echo $xml->competitioninformation->ladder[0]->attributes();

 

now of course, the above will always only pull the attribute from the first "ladder" node. changing 0 to 1 will give the second in the bunch.  just depends if this is to be dynamic or static.

actually ... ran into an new issue ...

 

instead of pulling both ladders at once, how can i pull on ladder at a time, how do i differentiate the 2 in code form.

 

I want to pull info from the first ladder, then (separately) pull info from the second ladder ... then the league is easy b/c there is only one.

the code provided will pull only the first ladder.  does not pull both.

 

and as noted in my post, switching the [0] to [1] will give you the second ladder.

 

now, this is a static method of pulling these values from the xml; you can always use foreach to loop through and display dynamically that way.

sorry, my post got messed up.  bbcode stepped in and did its thing.

 

what i meant was if you change [ 0] to [ 1], you can see the second ladder value in the xml file.

 

and i don't follow what you're asking.

 

what exactly are you trying to achieve, and then maybe i can help you.  do you only want to pull the first ladder, or are you now looking to be able to pick and choose?  and will there ever be more than 2 ladder values in any given xml file?

-  please see the attached file for the code i currently have...

 

-  here is the result from the code ... http://testing.a3designs.com/

 

 

as you can see the issue i have run into is that the ladder name shows up fine on the first ladder, but there is an issue with the second, and the league is also fine.

 

Yes there can always be more than 1 ladder/league, etc... in these XMLs

 

Thanks for your help.

 

[attachment deleted by admin]

<?php
$url = 'http://www.teamwarfare.com/xml/viewteam_v2.asp?team=Late+Nite+Commandos';

$xml = simplexml_load_file($url);

echo $xml->competitioninformation->ladder[0]->attributes();
?>

This will pull the first ladder only, as stated by MrMarcus. I'm assuming to pull the second ladder..

You'd do the same code.. but using

echo $xml->competitioninformation->ladder[1]->attributes();

instead. This will pull the second ladder?

Sorry if I'm wrong, I haven't ever worked with XML

I dont know exactly whats being displayed, but alot of info is on there. With an error at the bottom.

Fatal error: Call to a member function tablerender() on a non-object in /home/ash71360/public_html/SITE_LNC/e107_plugins/A3-TWL_menu/A3-TWL_menu.php on line 118

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.