Link to home
Start Free TrialLog in
Avatar of andre72
andre72

asked on

Pasing XML Document on CE

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
Avatar of BigRat
BigRat
Flag of France image

>>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.
Avatar of andre72
andre72

ASKER

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)
                     {
                     }
             }
ASKER CERTIFIED SOLUTION
Avatar of BigRat
BigRat
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of andre72

ASKER

Bis auf Deinen Tippfehler perfekt - mit foreach (XmlAttribute attNode in node.Attributes) geht es. Vielen Dank