Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Feb 2009
    Location
    Mosjøen, Norway
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post DOM XML Parser problems.

    Hi there guys! Maybe some of the bright minds out there know a solution to my current..nuisance.

    I'm trying to import different profiles from the World of Warcraft Armory (some profiler thing for a game I play.) that uses XML as their informaton scheme. The problem I'm having lies in duplicate entries? I'm not sure if that's the right way to say it, anyhow, I'm using the DOMDocument parser that comes native with PHP to extract my information but, whenever there are multiple tags like these 2 examples:
    Code:
        <character battleGroup="Rampage" charUrl="r=Neptulon&amp;n=Nieeru" class="Mage" classId="8" faction="Alliance" factionId="0" gender="Female" genderId="1" guildName="CoX" guildUrl="r=Neptulon&amp;n=CoX&amp;p=1" lastModified="March 11, 2009" level="80" name="Nieeru" points="3160" prefix="" race="Draenei" raceId="11" realm="Neptulon" suffix="">
          <arenaTeams>
            <arenaTeam battleGroup="Rampage" created="1229472000000" faction="Alliance" factionId="0" gamesPlayed="0" gamesWon="0" lastSeasonRanking="0" name="The Popcorns" ranking="0" rating="1500" realm="Neptulon" realmUrl="b=Rampage&amp;r=Neptulon&amp;ts=2&amp;t=The+Popcorns&amp;ff=realm&amp;fv=Neptulon&amp;select=The+Popcorns" season="0" seasonGamesPlayed="0" seasonGamesWon="0" size="2" teamSize="2" teamUrl="r=Neptulon&amp;ts=2&amp;t=The+Popcorns&amp;select=The+Popcorns" url="r=Neptulon&amp;ts=2&amp;t=The+Popcorns&amp;select=The+Popcorns">
              <emblem background="ff4366c2" borderColor="ffdaace0" borderStyle="6" iconColor="ff70f2ad" iconStyle="40"/>
              <members>
                <character battleGroup="" charUrl="r=Neptulon&amp;n=Nieeru" class="Mage" classId="8" contribution="1500" gamesPlayed="0" gamesWon="0" gender="Female" genderId="1" guild="CoX" guildId="3217918" guildUrl="r=Neptulon&amp;n=CoX&amp;p=1" name="Nieeru" race="Draenei" raceId="11" seasonGamesPlayed="0" seasonGamesWon="0" teamRank="0"/>
                <character battleGroup="" charUrl="r=Neptulon&amp;n=Nilor" class="Paladin" classId="2" contribution="1500" gamesPlayed="0" gamesWon="0" gender="Female" genderId="1" guild="CoX" guildId="3217918" guildUrl="r=Neptulon&amp;n=CoX&amp;p=1" name="Nilor" race="Draenei" raceId="11" seasonGamesPlayed="0" seasonGamesWon="0" teamRank="1"/>
              </members>
            </arenaTeam>
          </arenaTeams>
        </character>
    and this
    Code:
    <skill key="enchanting" max="450" name="Enchanting" value="441"/>
    <skill key="tailoring" max="450" name="Tailoring" value="435"/>
    It makes my life a living hell, trying to fetch the information. I'm not sure if looping is the way to go, if so, I'm doing something extremely wrong. I've tried using IF statements to filter out information, but, it just keeps, in the first example, putting out the name "Nieeru" twice, for example.

    In the latter code statement, I've tried to set 4 variables to null by start. name1, value1, name2 and value2. Using IF statements to set them and such, but, all of them seems to automatically just over-write themselves to the last if statement, no matter what I try.
    Code:
    $pfs = $xml->getElementsByTagName("skill");
    foreach($pfs as $profession) {
    	$name1 = null;
    	$value1 = null;
    	# -- Get the first profession name & value
    	if($profession->getAttribute("name") == "Alchemy" && $profession->getAttribute("name") != $name1) {
    		$name1 = $profession->getAttribute("name");
    		$value1 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Blacksmithing" && $profession->getAttribute("name") != $name1) {
    		$name1 = $profession->getAttribute("name");
    		$value1 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Enchanting" && $profession->getAttribute("name") != $name1) {
    		$name1 = $profession->getAttribute("name");
    		$value1 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Engineering" && $profession->getAttribute("name") != $name1) {
    		$name1 = $profession->getAttribute("name");
    		$value1 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Herbalism" && $profession->getAttribute("name") != $name1) {
    		$name1 = $profession->getAttribute("name");
    		$value1 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Mining" && $profession->getAttribute("name") != $name1) {
    		$name1 = $profession->getAttribute("name");
    		$value1 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Inscription" && $profession->getAttribute("name") != $name1) {
    		$name1 = $profession->getAttribute("name");
    		$value1 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Jewelcrafting" && $profession->getAttribute("name") != $name1) {
    		$name1 = $profession->getAttribute("name");
    		$value1 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Leatherworking" && $profession->getAttribute("name") != $name1) {
    		$name1 = $profession->getAttribute("name");
    		$value1 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Skinning" && $profession->getAttribute("name") != $name1) {
    		$name1 = $profession->getAttribute("name");
    		$value1 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Tailoring" && $profession->getAttribute("name") != $name1) {
    		$name1 = $profession->getAttribute("name");
    		$value1 = $profession->getAttribute("value");
    	}
    	$name2 = null;
    	$value2 = null;
    	# -- Get the second profession name & value
    	if($profession->getAttribute("name") == "Alchemy" && $profession->getAttribute("name") != $name2) {
    		$name2 = $profession->getAttribute("name");
    		$value2 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Blacksmithing" && $profession->getAttribute("name") != $name2) {
    		$name2 = $profession->getAttribute("name");
    		$value2 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Enchanting" && $profession->getAttribute("name") != $name2) {
    		$name2 = $profession->getAttribute("name");
    		$value2 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Engineering" && $profession->getAttribute("name") != $name2) {
    		$name2 = $profession->getAttribute("name");
    		$value2 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Herbalism" && $profession->getAttribute("name") != $name2) {
    		$name2 = $profession->getAttribute("name");
    		$value2 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Mining" && $profession->getAttribute("name") != $name2) {
    		$name2 = $profession->getAttribute("name");
    		$value2 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Inscription" && $profession->getAttribute("name") != $name2) {
    		$name2 = $profession->getAttribute("name");
    		$value2 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Jewelcrafting" && $profession->getAttribute("name") != $name2) {
    		$name2 = $profession->getAttribute("name");
    		$value2 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Leatherworking" && $profession->getAttribute("name") != $name2) {
    		$name2 = $profession->getAttribute("name");
    		$value2 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Skinning" && $profession->getAttribute("name") != $name2) {
    		$name2 = $profession->getAttribute("name");
    		$value2 = $profession->getAttribute("value");
    	} elseif($profession->getAttribute("name") == "Tailoring" && $profession->getAttribute("name") != $name2) {
    		$name2 = $profession->getAttribute("name");
    		$value2 = $profession->getAttribute("value");
    	}
    }
    I'm not really sure what to do, whether or not to go the way I've already done. (Using DOMDocument, or using the event-based API.)

    It's really starting to get on my nerves now, after strugling with this problem for the last week. So I'm at a loss.

    Does anyone have any ideas or something, that can help me on my way?
    Any help would be greatly appreciated!

    Cheers,
    - Mentally.

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,509
    Thanks
    8
    Thanked 1,090 Times in 1,081 Posts
    What is supposed to happen with the data you read?
    Are you displaying it on the screen, saving it somewhere?

    I think how you parse, and what the end result is supposed
    to be will change the answer on how to do it.

    I don't know anything about war-games, so I'm not sure if
    the top XML example is data for one "battlegroup", and there
    are many of those?

    So you display the data by "battlegroup"?

  • #3
    New Coder
    Join Date
    Feb 2009
    Location
    Mosjøen, Norway
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ah, hi there. At the moment, what I'm trying to do is break down pieces of information from the downloaded XML sheet and pull it into a database.

    The battlegroup thing. The servers in World of Warcraft are split up in different Battlegroups. A cluster of servers in one group where people from all those servers can bash their heads together in PvP-Battleground instances and Arena matches, etc. That's basically what it's for. The data I was wanting to parse is in the <character> tab, but as it turns out, if you look at the source within the <ArenaTeams> tabs, there's also <character> tabs so when trying to use:
    Code:
    $xml->getElementsByTagName("character");
    $xml->getAttribute("name");
    It automatically fetches anything that maches it, even if it's within the <ArenaTeam> bracket.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •