Re: retrieving an attribute from a node in a nodelist

Tech-Archive recommends: Fix windows errors by optimizing your registry



here is an example from my code
private void LoadExtensions( string url, bool merging,bool isString )

{

ArrayList extens = new ArrayList();

XmlTextReader reader;

if(!isString)

{

Stream stream = MakeStream(url); // this bascially opens the file that has
xml

reader = new XmlTextReader(stream);//this reads the stream (file)

}

else

{

reader = new XmlTextReader(url); //if its url then i don t need to open the
file etc

}

XmlDocument doc = new XmlDocument();

doc.Load(reader);

XmlNodeList nodeLst = doc.GetElementsByTagName("WAMiConf"); //top node


if( nodeLst.Count != 1 )

throw new Exception("Invalid XML data. A single WAMiConf tag is required.");

mErrors = new ArrayList();

foreach( XmlNode topNode in nodeLst )

{

foreach( XmlNode extNode in topNode.ChildNodes )

{

if( extNode.Name == "Extensions" )

extens.AddRange( ParseExtensions( extNode ) );

}

}


}


private ArrayList ParseExtensions( XmlNode extenNode )

{

ArrayList extens = new ArrayList();

foreach( XmlNode node in extenNode.ChildNodes )

{

if( node.Name.ToLower() == "extension" )

{

InternalExtension extension = new InternalExtension();

// Look for optional "group" and "maxoccurs" attributes

if( node.Attributes["group"] != null )

extension.GroupName = node.Attributes["group"].Value;

foreach( XmlNode child in node.ChildNodes )

{

if( child.Name.ToLower() == "name" )

extension.Name = child.InnerText;

if( child.Name.ToLower() == "number" )

extension.ExtensionNumber = child.InnerText;

}


}

return extens;

}



forgive me if there are syntax or mismatching braces i just copied and
cleaned up the code for simplicity, otherwise it would be two pages long and
hard to understand.

HTH


.



Relevant Pages

  • Navigating an XML Document
    ... I am struggling to find a solution. ... foreach (XmlNode cNode in node.ChildNodes) ... I am developing in .NET 1.1 with the latest version of windows mobile ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Navigating an XML Document
    ... in .NET 1.1 for compact framework. ... XmlNode xnRoot = xdConfig.DocumentElement; ... XmlDocument xmlSourceDoc = new XmlDocument; ... foreach ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Filtering a XmlNodeList
    ... foreach (XmlNode node in list) ... otherparams) ... Anthony Jones - MVP ASP/ASP.NET ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Filtering a XmlNodeList
    ... foreach (XmlNode node in list) ... otherparams) ... if (criteria using otherparams) ...
    (microsoft.public.dotnet.languages.csharp)