Pages: [1] :: one page |
|
Author |
Thread Statistics | Show CCP posts - 0 post(s) |

Vistilantus
Caldari You're Doing It Wrong
|
Posted - 2008.10.14 21:22:00 -
[1]
hey folks, i've been messing around with coding an api parsing program for my own use but i`m stuck and was wondering if anyone had any ideas.
Code looks like this - (data is being read directly from the api site using appropriate userid, keyid and charid)
XmlDocument xDoc = new XmlDocument(); xDoc.LoadXml(s); XmlNodeList characterID = xDoc.GetElementsByTagName("characterID"); XmlNodeList name = xDoc.GetElementsByTagName("name"); XmlNodeList race = xDoc.GetElementsByTagName("race"); XmlNodeList bloodLine = xDoc.GetElementsByTagName("bloodLine"); XmlNodeList gender = xDoc.GetElementsByTagName("gender"); characterIdTextBox.Text = characterID.ToString(); nameTextBox.Text = name.ToString(); raceTextBox.Text = race.ToString(); bloodLineTextBox.Text = bloodLine.ToString(); genderTextBox.Text = gender.ToString();
The text boxes only show "System.Xml.XmlElementList" and i was wondering if anyone knew how to get the text boxes to display the correct attributes from the api site.
I've been at this all nite so far and it's time to go sleep, if you need any more info, post here and i`ll pick it up tomorrow.
thank's folks. ___________________________________________________ ~Vistilantus |

Vessper
Indicium Technologies
|
Posted - 2008.10.14 23:28:00 -
[2]
An XMLNodeList is a collection of nodes so you'd have to be a bit more specific as to which node you wish to view. I've not tried it but you might want to try something like:
nameTextBox.Text = name(0).InnerXML
This should pick up the first node in the "name" XMLNodeList and displays the data between the tags. This should work ok assuming that there is only 1 "name" tag in the XML(which there should be!)
- - -
EveHQ Character App | Item Database |

Mulasha Sinae
Amarr Kismet Foundation Exxxotic
|
Posted - 2008.10.15 00:00:00 -
[3]
When using XmlDocument, you have to be specific as to what nodes you're getting. From that code, you're just getting a list of the nodes that are named "characterID," etc.
Here's how you would do it, although you would want to check for NullReferenceExceptions, because if the node doesn't exist, you get a nasty error.
Sample XML: <CharacterSheet> __<result> ____<characterID>133713371337</characterID> ____<name>MAI NAEM IZ JIMMY</name> ____<race>Cat</race> ____<bloodLine>LOL</bloodLine> ____<gender>Male</gender> __</result> </CharacterSheet>
XmlDocument xml = new XmlDocument(); xml.LoadXml(s);
// This will get all the child nodes under the node <result />, // which will be for most of the API responses. XmlNode node = xml.GetElementsByTagName("result");
// Despite "node" looking like a single node, it is actually an // array that holds a bunch of other XmlNodes (or XmlElements). string characterId = node["characterID"].InnerText; string name = node["name"].InnerText; string race = node["race"].InnerText; string bloodline = node["bloodLine"].InnerText; string gender = node["gender"].InnerText;
Polymorphism comes into play a lot when using XmlDocument. You can use XmlNode, or XmlElement. I usually use XmlNode, although XmlElement seems better in the long run because XmlElement has the GetElementsByTagName method.
There is a bit of a more graceful way of doing it with XmlReader, but you can google that yourself. To access node attributes, for use in responses such as MemberTracking, just do the exact same thing, except with "node.Attributes["ATTRIBUTENAME"].InnerText;"
For example: <row characterID="133713371337" name="MAI NAEM IZ JIMMY" race="Cat" bloodLine="LOL" gender="Male" />
foreach (XmlNode node in xml.GetElementsByTagName("row")) { _____string characterId = node.Attributes["characterID"].InnerText; _____// Etc... }
Hope this helped!
|

Vistilantus
Caldari You're Doing It Wrong
|
Posted - 2008.10.15 10:13:00 -
[4]
Edited by: Vistilantus on 15/10/2008 10:16:51 Thank's alot for your replies guys,
I tried messing around using the code in the post above but, obviously, it didn't work right "out the box" after some fiddling, i came up with this :
___XmlDocument xml = new XmlDocument(); ___xml.LoadXml(s);
// This will get all the child nodes under the node <result />, // which will be for most of the API responses. ___XmlNodeList node = xml.GetElementsByTagName("result");
// Despite "node" looking like a single node, it is actually an // array that holds a bunch of other XmlNodes (or XmlElements). ___string characterId = node[0].ChildNodes[0].InnerText; ___string name = node[0].ChildNodes[1].InnerText; ___string race = node[0].ChildNodes[2].InnerText; ___string bloodline = node[0].ChildNodes[3].InnerText; ___string gender = node[0].ChildNodes[4].InnerText; ___characterIdTextBox.Text = characterId; ___nameTextBox.Text = name; ___raceTextBox.Text = race; ___bloodLineTextBox.Text = bloodline; ___genderTextBox.Text = gender;
This puts the data in exactly where i want. Does this look ok to you? Is there any other more efficient way of doing it?
Many thanks,
~Vist
edit - the part "string characterId = node["characterID"].InnerText;" node[] looks for an integer value which is why it wouldn't work straight up. obvisouly, i would prefer a way of retrieving the data by using the "name of field here" so any help on this would be appreciated. I just got the linkage for the EVEDev wiki so i`m gonna have a looksie there and see what i can find. ___________________________________________________ ~Vistilantus |

Mulasha Sinae
Amarr Kismet Foundation Exxxotic
|
Posted - 2008.10.15 10:47:00 -
[5]
Originally by: Vistilantus edit - the part "string characterId = node["characterID"].InnerText;" node[] looks for an integer value which is why it wouldn't work straight up. obvisouly, i would prefer a way of retrieving the data by using the "name of field here" so any help on this would be appreciated. I just got the linkage for the EVEDev wiki so i`m gonna have a looksie there and see what i can find.
I'm sorry, I left out one crucial thing in my code example.
In my first post, if you replace:
XmlNode node = xml.GetElementsByTagName("result");
with:
XmlNode node = xml.GetElementsByTagName("result")[0];
it should compile and allow you to use field names.
|

Vistilantus
Caldari You're Doing It Wrong
|
Posted - 2008.10.15 10:53:00 -
[6]
Edited by: Vistilantus on 15/10/2008 10:53:05 Fantastic! Thank you very much i now owe you bree/isk/both
Now to try pull data from XML _AND_ the data dump to display skills trained using the ID's
should be fun. No doubt i`ll be back asking lots of questions! ___________________________________________________ ~Vistilantus |

Mulasha Sinae
Amarr Kismet Foundation Exxxotic
|
Posted - 2008.10.15 17:30:00 -
[7]
Originally by: Vistilantus Edited by: Vistilantus on 15/10/2008 10:53:05 Fantastic! Thank you very much i now owe you bree/isk/both
Now to try pull data from XML _AND_ the data dump to display skills trained using the ID's
should be fun. No doubt i`ll be back asking lots of questions!
No problem at all. 
http://www.hikarikaiki.com/corptracker/_skilltree.xml is what I made for CorpTracker. It uses a PHP script and a local WAMP server to construct the file.
|
|
|
|
Pages: [1] :: one page |
First page | Previous page | Next page | Last page |