?
Solved

Pasing XML Document on CE

Posted on 2008-11-05
4
Medium Priority
?
311 Views
Last Modified: 2013-11-17
Hi,

I've a XML Document with a structur like this:
<?xml version="1.0" encoding="utf-8"?>
<screens>
  <test1 name="Kalender" bgimage="Menu2">
    <control id="1" event="My1_Click" xy="1" name="Raume" active="Pic2o" type="1" />
    <control id="2" event="My2_Click" xy="2" name="Kalender" active="Pic1o" type="1" />
    <control id="3" event="My3_Click" xy="3" name="Einnstellungen" active="Pic3o" type="1" />
  </test1>
  <test2 name="Raeume" bgimage="Menu">
    <control id="1" event="My1_Click" xy="1" name="Raume" active="Pic1o" type="1"/>
    <control id="2" event="My2_Click" xy="2" name="Kalender" active="Pic2o" type="1" />
    <control id="3" event="My3_Click" xy="3" name="Einnstellungen" active="Pic3o" type="1" />
  </test2>
  <test name="Test" bgimage="Menu">
    <control id="1" xy="1" name="Raume" type="2" width="50" height="100"/>
    <control id="2" xy="2" name="Kalender" type="3" width="250" height="20"/>
    <control xy="3" name="Einnstellungen" type="4" width="100" height="20"/>
    <control id="4" event="My1_Click" xy="2" name="Kalender" active="Pic2o" type="1" />
  </test>
</screens>

To access the nodes at the moment I use:
private static XmlDocument screens = new XmlDocument();
screens.Load(Globals.inipath + "screens.xml");
// Access node I need
XmlNodeList nodes = screens.SelectNodes("screens/test/control");
// Get Attributes
foreach (XmlNode node in nodes)
int ty = Convert.ToInt32(node.Attributes["type"].Value);
                switch (ty)
                {
                case 1:
                    ta = node.Attributes["event"].Value;
                    ...
                    break;
                 case 2:
                    wi = node.Attributes["width"].Value;
                    ...
                    break;
            {
}

Yes it works, but I've ever depending from the ID to select what Attributes I've to read.

Is there a way to access any Attribute included by a loop like XMLTextReader (MoveToNextAttribute) can do?
For sure I could complete change to XMLTextReader but I think than I've to miss SelectNodes.

Is it possbile to combinate both?
I'm developing with the CF 2.0 and can't upgrade it.

Thanks,

Andre
0
Comment
Question by:andre72
  • 2
  • 2
4 Comments
 
LVL 27

Expert Comment

by:BigRat
ID: 22885506
>>Yes it works, but I've ever depending from the ID to select what Attributes I've to read

I don't quite understand that sentence. You can explain ine German if you wish.

Secondly you select all control nodes and select the type attribute, then select on its value.

Node.Attributes is a NamedNodeMap which is a combination of an iterator (with item, nextNode and reset) and getQualifiedItem and getNamedItem methods. So if you can explain what you want to do exactly, it will be possible to do it.
0
 

Author Comment

by:andre72
ID: 22885569
Ok, Deutsch ist leichter ...
Also, jeder Control Eintrag hat ja eine unterschiedliche Anzahl an Attributen, diese heissen nun auch wiederum anders (mal event="", andere haben width="" usw.)

Mit dem XMLTextReader könnte ich das ja in einer Schleife durchlkaufen, müßte aber ebenso vorher meinen Knoten suchen (while (reader.Read()) während ich mit SelectNodes ja direkt entsprechenden Knoten anspreche (obwohl das intern wohl auch nichts anderes machen wird, als diesen in einer Schleife zu suchen).
Also was ich suche ist eigentlich folgend Möglichkeit:
nodes = screens.SelectNodes("screens/" + room + "/control");
foreach (XmlNode node in nodes)
            {
                     foreach(attribute in irgendwas)
                     {
                     }
             }
0
 
LVL 27

Accepted Solution

by:
BigRat earned 1000 total points
ID: 22885762
Node.attributes returns a NamedNodeMap which supports an iterator. The iterator will return nodes (of type attribute). The NamedNodeMap was introduced so that one could directly access the attribute nodes without have to get each individual node. So it goes :-

      foreach (XMLNode attNode in Node.Attributes)  
0
 

Author Closing Comment

by:andre72
ID: 31513488
Bis auf Deinen Tippfehler perfekt - mit foreach (XmlAttribute attNode in node.Attributes) geht es. Vielen Dank
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Screencast - Getting to Know the Pipeline
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question