Get value from XML - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Get value from XML (/showthread.php?tid=83276)
Get value from XML by SnuZZer on 04-19-2008 at 07:55 PM
Hey.
I haven't been working with XML for that long time, but I am now.
I'm trying to get the value, from the red strings in the following code, but I can't figure out how.
The XML is dynamic and doesn't have a permanent number of items, so I am doing a for();
The XML document.
code: <myxmldocument>
<items count="2">
<item id="22380">
<name>This is a test</name>
<quality>4</quality>
<icon>test_icon</icon>
</item>
<item id="18952">
<name>Simone's Head</name>
<quality>2</quality>
<icon>icon_for_testing</icon>
</item>
</items>
</myxmldocument>
My code:
code: var SendItems = "";
var Items = XMLmsg.selectSingleNode("myxmldocument//items");
var ItemLink = XMLmsg.selectSingleNode("myxmldocument//items//item");
if(Items != null)
{
for(var i = 0; i < Items.childNodes.length; i++)
{
Quality = Items.childNodes[i].childNodes[1].text; // Quality
SendItems += "[b]";
switch(Quality) // Name
{
case "0":
SendItems += "[c=#9d9d9d]" + Items.childNodes[i].childNodes[0].text + "[/c] ";
break;
case "1":
SendItems += "[c=#000000]" + Items.childNodes[i].childNodes[0].text + "[/c] ";
break;
case "2":
SendItems += "[c=#1eff00]" + Items.childNodes[i].childNodes[0].text + "[/c] ";
break;
case "3":
SendItems += "[c=#0070dd]" + Items.childNodes[i].childNodes[0].text + "[/c] ";
break;
case "4":
SendItems += "[c=#a335ee]" + Items.childNodes[i].childNodes[0].text + "[/c] ";
break;
case "5":
SendItems += "[c=#ff8000]" + Items.childNodes[i].childNodes[0].text + "[/c] ";
break;
case "6":
SendItems += "[c=#e6cc80]" + Items.childNodes[i].childNodes[0].text + "[/c] ";
break;
}
SendItems += "[/b]";
SendItems += "\n";
SendItems += ItemLink.childNodes[0].childNodes[i].text + "\n";
}
I hope, you can help me out of this problem.
Thanks in advance.
RE: Get value from XML by SnuZZer on 04-19-2008 at 08:46 PM
With a lot of searching and using of my little knowledge, I've figured out of to do this.
I've deleted ItemLink and now using Items.
Then I've replaced the following line:
SendItems += ItemLink.childNodes[0].childNodes[i].text + "\n";
to
SendItems += ItemLink.childNodes[i].getAttribute("id") + "\n";
So now my code looks like this:
code: var SendItems = "";
var Items = XMLmsg.selectSingleNode("myxmldocument//items");
if(Items != null)
{
for(var i = 0; i < Items.childNodes.length; i++)
{
Quality = Items.childNodes[i].childNodes[1].text; // Quality
SendItems += "[b]";
switch(Quality) // Name
{
case "0":
SendItems += "[c=#9d9d9d]" + Items.childNodes[i].childNodes[0].text + "[/c] ";
break;
case "1":
SendItems += "[c=#000000]" + Items.childNodes[i].childNodes[0].text + "[/c] ";
break;
case "2":
SendItems += "[c=#1eff00]" + Items.childNodes[i].childNodes[0].text + "[/c] ";
break;
case "3":
SendItems += "[c=#0070dd]" + Items.childNodes[i].childNodes[0].text + "[/c] ";
break;
case "4":
SendItems += "[c=#a335ee]" + Items.childNodes[i].childNodes[0].text + "[/c] ";
break;
case "5":
SendItems += "[c=#ff8000]" + Items.childNodes[i].childNodes[0].text + "[/c] ";
break;
case "6":
SendItems += "[c=#e6cc80]" + Items.childNodes[i].childNodes[0].text + "[/c] ";
break;
}
SendItems += "[/b]";
SendItems += "\n";
SendItems += SendItems += Items.childNodes[i].getAttribute("id") + "\n";
}
|