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
Share on other sites

LOL ... i see that...

 

what do you mean by $value ... again I am new so please be gentle !

 

The "value" i want to pull is the Battlefield: Bad Com.....

If you mean the value of that field there is no </...> in the XML.

Link to comment
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.

Link to comment
Share on other sites

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-

 

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

-  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]

Link to comment
Share on other sites

<?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

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.