Jump to content


Photo

LF Help: wowhead XML parser


  • Please log in to reply
3 replies to this topic

#1 Cigaras

Cigaras

    Von Kaiser

  • Members
  • 32 posts

Posted 08 December 2010 - 12:33 PM

Good day everyone.

I am SQL developer in real life (guild leader and affliction warlock in game if anyone cares), mostly work with SyBase products, have very little experience with C/C++ and close to no experience with PHP (assembled few pages using CMS's) and there is one thing regarding World of Warcraft that I would like to develop (or maybe there is one already but I can't find it): an application that would download items from wowhead.com servers to a local computer, in XML or JSON or similar format, but again I have close to no experience with web services or any other kind of http parsing, however on this forum I found a few programs that are able to do that like Simulationcraft and OptiGear, there are even source codes, but they are way to complicated to try to understand them by myself, so I am asking for help of elitist jerks community members.

For beginning I want very simple thing, a c/c++/php or any similar programing language procedure/function that would save info like http://www.wowhead.com/item=49623&xml to a local variable/file.

UPDATE: It looks I did it using php:
<?php
$xml = simplexml_load_string(file_get_contents('http://www.wowhead.com/item=49623&xml'));
print_r($xml);
?>

However this tooltip doesnt has stats tags in it, only <htmlTooltip> which is not very convenient to use and <jsonEquip> that needs adidtional decoding...

Anyone any ideas how to reach similar result in c/c++? and maybe someone knows how to get multilpe items from wowhead.com, not single one, like Armor - Items - World of Warcraft? Any help would be appreciated.

P.S. Sorry for my bad English, I am not a native speaker.

P.S.S. Sorry, wrong forum, this should be in Public Discussion threat, would be great if someone could move it there.

#2 dedmonwakeen

dedmonwakeen

    Bald Bull

  • Members
  • 1,302 posts

Posted 08 December 2010 - 02:59 PM

All the info you need is in the json fields. You have to parse it out.

Doing this from C++ is non-trivial. You need a package to manage the http protocol and a package to parse the XML.

However, downloading public libraries for these functions is a bit like pushing in a thumb-tack with a sledgehammer.

In SimC I elected to implement the http protocol for posix platforms and wrap the windows utility. I also elected to write a super-simple xml parser/interrogator. Feel free to start from sc_http.cpp and sc_xml.cpp. Simply remove usage of the sim_t, threading, caching, and whats left over is pretty small.

#3 Cigaras

Cigaras

    Von Kaiser

  • Members
  • 32 posts

Posted 09 December 2010 - 06:22 AM

Thanks for reply, but I am afraid your code is too complicated for me, I know only basics of c++, very early basics...

As of using PHP:
<?php
$url = 'http://www.wowhead.com/item=49623&xml';
$xml = simplexml_load_string(file_get_contents($url));
$json = '{'.$xml->item->jsonEquip.'}';
var_dump(json_decode($json, true));
?>

and result:
array(25) {
 ["classes"]=> int(35)
 ["critstrkrtng"]=> int(114)
 ["displayid"]=> int(65153)
 ["dmgmax1"]=> int(1609)
 ["dmgmin1"]=> int(965)
 ["dmgtype1"]=> int(0)
 ["dps"]=> float(347.8)
 ["dura"]=> int(145)
 ["hastertng"]=> int(114)
 ["maxcount"]=> int(1)
 ["mledmgmax"]=> int(1609)
 ["mledmgmin"]=> int(965)
 ["mledps"]=> float(347.8)
 ["mlespeed"]=> float(3.7)
 ["nsockets"]=> int(3)
 ["reqlevel"]=> int(80)
 ["sellprice"]=> int(504762)
 ["slotbak"]=> int(17)
 ["socket1"]=> int(2)
 ["socket2"]=> int(2)
 ["socket3"]=> int(2)
 ["socketbonus"]=> int(3312)
 ["speed"]=> float(3.7)
 ["sta"]=> int(268)
 ["str"]=> int(196)
}
How am I supposed to know that "socketbonus":3312 stands for +8 str...

#4 dedmonwakeen

dedmonwakeen

    Bald Bull

  • Members
  • 1,302 posts

Posted 09 December 2010 - 12:09 PM

For enchants and reforging we have static arrays to translate the encoding.
For the socket bonus we parse the tool-tip.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users