xboxscene.org forums

Author Topic: Just Some Quick Q's  (Read 96 times)

ZogoChieftan

  • Archived User
  • Jr. Member
  • *
  • Posts: 54
Just Some Quick Q's
« on: February 03, 2004, 10:36:00 PM »

yourwishismine:
You mentioned that in the previous release of my toolbox there are some bugs in the config.xml file can you please tell me which tags are affected and what is the error that you get when you launch the application.
anyone:
Can someone please tell me the proper procedure for loading in xml files using vb.net cause i've tried and it's difficult.

From ZogoChieftan
Logged

ZogoChieftan

  • Archived User
  • Jr. Member
  • *
  • Posts: 54
Just Some Quick Q's
« Reply #1 on: February 03, 2004, 11:18:00 PM »

sounds good 2 me thanks.
Logged

morpheous1777

  • Archived User
  • Jr. Member
  • *
  • Posts: 53
Just Some Quick Q's
« Reply #2 on: February 04, 2004, 12:04:00 AM »

I know what ya mean, Ive been stumped for a while now on how to load an xml file in vb.net
Logged

unleashx

  • Archived User
  • Hero Member
  • *
  • Posts: 621
Just Some Quick Q's
« Reply #3 on: February 04, 2004, 06:51:00 AM »

CODE
//Add reference to XML
using System.Xml;

...
XmlDocument doc = new XmlDocument();
//XmlString must contain a valid xml string
doc.LoadXml(XmlString);


That's all there is to loading an xml.

To search for certain tags:
CODE
XmlNodeList xmlNList = doc.GetElementsByTagName("Image");
XmlElement listElement;
   for (int i = 0; i< xmlNList.Count; i++)
   {
 listElement = xmlNList.Item(i) as XmlElement;
 if (listElement != null)
 {
    //...do your thing
    //you can use the GetAttribute method to query attributes. i.e.: listElement.GetAttribute("Source"));
 }
   }


I'm also using a generic function which you may find usefull

CODE
private XmlElement FindChildElement(XmlElement pElement, string ElementName, string AttributeValue, bool Detach)
{
   if (pElement == null || (ElementName == null || ElementName.Length == 0))
 return null;

   XmlNodeList xmlNList = pElement.SelectNodes(ElementName);     for (int i = 0; i   {
 if (AttributeValue.Length >0)
 {
    //modify this code and loop thru available attributes
    if (!xmlNList.Item(i).Attributes["Text"].Value.Equals(AttributeValue))
   continue;
 }

 if (Detach)
 {
    XmlElement pReturn = xmlNList.Item(i).Clone() as XmlElement;
    pElement.RemoveChild(xmlNList.Item(i));
    return pReturn;
 } else
    return (xmlNList.Item(i) as XmlElement);
   }
   return null;
 
}


An example showing how to use the above code:
CODE
XmlElement listElement = null;
//let's find the Menu element
listElement = FindChildElement((doc.ChildNodes[0] as XmlElement), "Menu", "", false); //ChildNodes[0] is the root of the document
//let's find the Submenu called 'Games"
listElement = FindChildElement(listElement, "List", "Games", false);


Note: For brevity's sake, all error handlers have been removed.
Logged