Autor Beitrag
Flop
Hält's aus hier
Beiträge: 12



BeitragVerfasst: So 25.04.10 12:23 
hab da mal wieder ein problem... (Trotz stunden langem googeln und VC# 2008 Grundlagen und Profiwissen) X(
Mhh, wo fang ich am besten bei meiner Problembeschreibung an? ..
Ich wollte gerne eine XML Datei die irgentwo auf meinem PC liegt mit einem open file dialog öffnen. Die datei die ich dann geöffnet habe, soll ein paar knoten auslesen und sie in eine textbox darstellen. Diese "werte" die ich aus der XML datei auslese, soll ich natürlich auch ändern können. Also sollte man in die Textbox gehen können und den wert ändern und speichern.
Zum besseren verständnis, hier ein ausschnitt der XML:
ausblenden volle Höhe XML-Daten
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
<?xml version="1.0" encoding="utf-8"?>
<profile>
  <options>
    <!-- Try the bot with a new char mage                 -->
    <!-- At the pioneer village. Use demo.xml waypoint file -->
    <option name="HP_LOW"      value="85" />
    <option name="MP_LOW_POTION"  value="30" />
    <option name="HP_LOW_POTION"  value="55" />
    <option name="USE_HP_POTION"  value="best" />  <!-- potion select strategy: best|minstack -->
    <option name="USE_MANA_POTION"  value="best" />  <!-- potion select strategy: best|minstack -->

    <!-- Rest if HP or Mana is below that level -->
    <option name="HP_REST" value="20" />
    <option name="MP_REST" value="20" />

    <!-- Shopping options, how many of what do you want to keep in your inventory -->
              <option name="HEALING_POTION" value="190" />
              <option name="MANA_POTION" value="200" />
              <option name="ARROW_QUIVER" value="0" />
              <option name="THROWN_BAG" value="0" />
              <option name="POISON" value="0" />
              <option name="INV_AUTOSELL_ENABLE" value="true" />
              <option name="INV_AUTOSELL_FROMSLOT" value="55" />
              <option name="INV_AUTOSELL_TOSLOT" value="60" />
              <option name="INV_AUTOSELL_QUALITY" value="white" />
              <option name="INV_AUTOSELL_IGNORE" value=""/>
              <option name="DEBUG_AUTOSELL" value="true" />

    <!-- either false or arrow or thrown -->
    <option name="RELOAD_AMMUNITION" value="false" />  <!-- false|arrow|thrown -->

    <!-- Combat options -->
    <option name="COMBAT_TYPE"      value="" />  <!-- leave empty or choose ranged/melee if not using class default -->
    <option name="COMBAT_RANGED_PULL" value="true" /> <!-- only important for melees -->
    <option name="COMBAT_DISTANCE"  value="200" />
    <option name="MAX_FIGHT_TIME"   value="15" />  <!-- Max time without damage before break -->
    <option name="DOT_PERCENT"      value="90" />
    <option name="ANTI_KS"          value="true" />

    <!-- Attack monsters 3 levels above or 10 below your level -->
    <option name="TARGET_LEVELDIF_ABOVE" value="3" />
    <option name="TARGET_LEVELDIF_BELOW" value="10" />

    <!-- Waypoint and movement settings -->
    <option name="WAYPOINTS"    value="Flop31" />  <!-- leave empty to show a list -->
    <option name="RETURNPATH"    value="" />
    <option name="PATH_TYPE"    value="waypoints" />  <!-- waypoints | wander -->
    <option name="WANDER_RADIUS"    value="500" />
    <option name="WAYPOINT_DEVIATION"  value="0" />
    <option name="QUICK_TURN"     value="false" />

    <!-- Loot settings -->
    <option name="LOOT"             value="true" />
    <option name="LOOT_IN_COMBAT"   value="true" />
    <option name="LOOT_DISTANCE"    value="100" />
    <option name="LOOT_PAUSE_AFTER"   value="3" />    <!-- probability in % for a short rest -->

    <!-- Log out and resurrect settings -->
    <option name="LOGOUT_TIME"       value="0" />  <!-- in minutes, 0 = timer disabled -->
    <option name="LOGOUT_SHUTDOWN"    value="false" />
    <option name="LOGOUT_WHEN_STUCK"  value="true" />
    <option name="RES_AUTOMATIC_AFTER_DEATH" value="true" />
    <option name="MAX_DEATHS" value="10" /> <!-- Log out after this many deaths -->

    <!-- For more options and documentation see the RoM Bot Wiki:  -->
    <!-- http://www.solarstrike.net/wiki/index.php5?title=RoM_Bot  -->

  </options>

  <friends>
    <!-- names of friends we help fighting or enemys we don't want to attack -->
    <!-- for umlauts use \129 (ue),\132 (ae),\148 (oe) e.g. K\132fer       -->
    <friend name="MyOtherCharacter1" />
    <friend name="MyOtherCharacter2" />
    <friend name="Elite_Mob_Name1" />
    <friend name="Elite_Mob_Name2" />
  </friends>

  <mobs>
    <!-- names of mobs we want to attack         -->
    <!-- if no names defined we will attack all mobs  -->
    <mob name="" />
    <mob name="" />
    <mob name="" />
  </mobs>

  <hotkeys>
    <!-- to communicate with the RoM API / define ingame dummy macro at place 1 -->
    <hotkey name="MACRO"      modifier="" key="VK_0" />
  </hotkeys>

  <!-- define your skills depending from your actual primary class -->
  <!-- see the example for a priest/mage                         -->
  <!-- delete skills you don't have or don't want to use.        -->
  <!-- For more skills to use see /database/skills.xml           -->
  <!-- demo skills for LvL 1 character for all classes           -->
  <skills_priest>
    <skill name="PRIEST_SOUL_SOURCE"   modifier="" hotkey="VK_4" priority="110" inbattle="true" hpper="15" />
    <skill name="PRIEST_HOLY_AURA"   modifier="" hotkey="VK_7" priority="100" inbattle="true" hpper="24" />
    <skill name="PRIEST_URGENT_HEAL"   modifier="" hotkey="VK_2" priority="100" hpper="30"  />
    <skill name="PRIEST_REGENERATE"  modifier="" hotkey="VK_6" priority="90" />
    <skill name="PRIEST_RISING_TIDE"   modifier="" hotkey="VK_3" priority="80" />
    <skill name="MAGE_FIREBALL"      modifier="" hotkey="VK_8" priority="70" />
    <skill name="PRIEST_WAVE_ARMOR"  modifier="" hotkey="VK_5" priority="40"  inbattle="true" />
    <!--skill name="PRIEST_SOUL_BOND"   hotkey="VK_T" priority="30" /> -->
    <!--skill name="PRIEST_MAGIC_BARRIER" hotkey="VK_F" priority="20" rebuffcut="60" inbattle="false" /> -->
  </skills_priest>

  <skills_warrior>
    <skill name="WARRIOR_SLASH"        modifier="" hotkey="VK_2" priority="90" />
    <skill name="WARRIOR_PROBING_ATTACK" modifier="" hotkey="VK_4" priority="80" />
    <skill name="WARRIOR_OPEN_FLANK"   modifier="" hotkey="VK_5" priority="70" />
  </skills_warrior>

  <skills_scout>
    <skill name="SCOUT_SHOT"      modifier="" hotkey="VK_2" priority="90" />
    <skill name="SCOUT_AUTOSHOT"  modifier="" hotkey="VK_4" priority="80" />
    <skill name="SCOUT_WIND_ARROWS" modifier="" hotkey="VK_5" priority="70" />
  </skills_scout>

  <skills_rogue>
    <skill name="ROGUE_SHADOWSTAB"  modifier="" hotkey="VK_2" priority="90" />
    <skill name="ROGUE_LOW_BLOW"  modifier="" hotkey="VK_4" priority="80" />
  </skills_rogue>

  <skills_mage>
    <skill name="MAGE_FLAME"            modifier="" hotkey="VK_1" priority="80" />
    <skill name="MAGE_ELECTROSTATIC_CHARGE" modifier="" hotkey="VK_4" hpper="35" priority="110" inbattle="true"  />
              <skill name="MAGE_LIGHTNING"  hotkey="VK_3" priority="60" cooldown="20" />
    <skill name="MAGE_ELEMENTAL_CATALYST" modifier="" hotkey="VK_9" priority="30" inbattle="true" />
  </skills_mage>

  <skills_knight>
    <skill name="KNIGHT_HOLY_STRIKE"  modifier="" hotkey="VK_3" priority="90" />
    <skill name="KNIGHT_HOLY_SHIELD"  modifier="" hotkey="VK_4" priority="80" inbattle="true" hpper="15" />
    <skill name="KNIGHT_HOLY_SEAL"  modifier="" hotkey="VK_5" priority="70" />
    <skill name="KNIGHT_PUNISHMENT"   modifier="" hotkey="VK_2" priority="60" />
  </skills_knight>

  <skills_warden>
    <skill name="WARDEN_CHARGED_CHOP"  modifier="" hotkey="VK_2" priority="90" />
    <skill name="WARDEN_ENERGY_ABSORB"  modifier="" hotkey="VK_3" priority="80" inbattle="true" hpper="25" />
  </skills_warden>

  <skills_druid>
    <skill name="DRUID_RECOVER"      modifier="" hotkey="VK_2" priority="90" hpper="30" />
    <skill name="DRUID_EARTH_ARROW"  modifier="" hotkey="VK_3" priority="80" />
  </skills_druid>

  <onLoad><![CDATA[
    -- Additional Lua code to execute after loading the profile
    -- and before the bot starts. e.g. You could overwrite profile settings here
    -- like: changeProfileOption("HP_REST", 60);
  ]]></onLoad>

  <onDeath><![CDATA[
    -- Additional Lua code to execute on death
    -- pauseOnDeath(); -- Stop the script
    -- player:logout();  -- logout
  ]]></onDeath>

  <onLeaveCombat><![CDATA[
    -- Additional Lua code to execute after killing an enemy
  ]]></onLeaveCombat>

  <onLevelup><![CDATA[
    -- Additional Lua code to execute after having a levelup
    -- and levelup the skills for a new character (mage or priest recommended)
    -- e.g. sendMacro("SetSpellPoint(_tabnr, _skillnr);"); would levelup a skill
  ]]></onLevelup>

  <onSkillCast><![CDATA[
    -- Additional Lua code to execute when casting a skill
    -- Note: arg1 contains the skill being used.
    -- i.e. arg1.Name will be the name of the skill being cast
    -- e.g.:
    --if( 15 > player.HP/player.MaxHP*100 ) then
    --  player:cast("PRIEST_SOUL_SOURCE");
    --elseif( 25 > player.HP/player.MaxHP*100 ) then
    --  player:cast("PRIEST_HOLY_AURA");
    --  player:cast("PRIEST_URGENT_HEAL");
    --  player:cast("PRIEST_URGENT_HEAL");
  ]]></onSkillCast>
</profile>



Wie kann ich jetzt z.B. nur von:
ausblenden XML-Daten
1:
<option name="HP_LOW_POTION"  value="55" />					

die Value auslesen ?
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: So 25.04.10 13:29 
Hallo,

für das Bearbeiten von Xml-Dateien gibt es in .NET die Klasse XDocument.

Damit kannst du deine Datei einlesen: XDocument.Load(<filename>);

Um zu den gewünschten Node zu navigieren gibt es unterschiedliche Methoden. Zum einen könntest du wirklich im Kote über die einzelnen Elemente navigieren: doc.Root.Element("profile").Element("options").. Das ist aber ziemlich umständlich.

Deshalb Rate ich dir XPath zu verwenden. Für XElement befindet sich eine passende Extension im Namespace System.LINQ.XPath;

Schau es dir mal an, vlt. hilft es schon. Ich muss erstmal raus in die Sonne :) Heute gibts dann eine genauere Hilfestellung.

Gruß
Flop Threadstarter
Hält's aus hier
Beiträge: 12



BeitragVerfasst: So 25.04.10 16:34 
user profile icondanielf hat folgendes geschrieben Zum zitierten Posting springen:
Hallo,

für das Bearbeiten von Xml-Dateien gibt es in .NET die Klasse XDocument.

Damit kannst du deine Datei einlesen: XDocument.Load(<filename>);

Um zu den gewünschten Node zu navigieren gibt es unterschiedliche Methoden. Zum einen könntest du wirklich im Kote über die einzelnen Elemente navigieren: doc.Root.Element("profile").Element("options").. Das ist aber ziemlich umständlich.

Deshalb Rate ich dir XPath zu verwenden. Für XElement befindet sich eine passende Extension im Namespace System.LINQ.XPath;

Schau es dir mal an, vlt. hilft es schon. Ich muss erstmal raus in die Sonne :) Heute gibts dann eine genauere Hilfestellung.

Gruß


Komm auch grad aus der Sonne wieder und siehe da , Sonnenbarnd ...

Also ich hab mir da smal angeguckt aber überhaupt nicht verstanden.
Könntest du mal ein kleines beispiel machen für die value aus der XML datei die ich gepostet habe ?

Ich kann bis jetzt nur den pfad auslesen wo die XML datei liegt .. :D

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
        private void button1_Click(object sender, EventArgs e)
        {
            

            XmlTextReader textReader = new XmlTextReader("C:\\Floppixx.xml");

            textReader.Read();

            while (textReader.Read())
            {


                textReader.MoveToElement();

                listBox1.Items.Add("XmlTextReader Properties Test");


                textBox1.Text = ("Base URI:" + textReader.BaseURI);
            }


Das bringt mir aber leider nix .. :D
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: Mo 26.04.10 07:22 
Ja, das bringt nichts ;)

Um ein Xml in Baustruktur (DOM) einzulesen benötigst du die von mir erwähnte Klasse XDocument, ehemals XmlDocument.
ausblenden C#-Quelltext
1:
XDocument xmlDoc = XDocument.Load("path.xml");					

Wie bereits erwähnt, kannst du die Navigation über xmlDoc.Root.Element("name").Element("subname") machen. Dies ist vor Allem bei komplexeren Xml-Strukturen sehr umständlich. Um an gewisse Element innerhalb eines Xml-Dokument zu kommen gibt es XPath.

Für XDocument bzw. XElement musst du dein Namespace System.Xml.XPath einbinden (using System.Xml.XPath;). Danach stehen dir vier erweitere Methoden zur Verfügung (CreateNavigator, XPathEvaluate, XPatSelectElement, XPathSelectElements). Dich interessiert in diesem Fall XPathSelectElement, welches du direkt auf das XDocument anwenden kannst.
ausblenden C#-Quelltext
1:
xmlDoc.XPathSelectElement("xpath-ausdruck");					

Das zurückgelieferte Element kann nun bearbeitet werden.

In deinem Fall könnte der XPath-Ausdruck so aussehen:
ausblenden C#-Quelltext
1:
2:
3:
XElement ersteOption = xmlDoc.XPathSelectElement("/profile/options/option[position()=1]");

XElement useHpOption = xmlDoc.XPathSelectElement("/profile/options/option[@name='USE_HP_POTION']");


Um nun einen Attributwert eines Knoten zu erhalten/zu bearbeiten muss du das Property Attribute verwenden:
ausblenden C#-Quelltext
1:
string value = ersteOption.Attribute("value").Value;					

Das setzen erfolgt analog:
ausblenden C#-Quelltext
1:
ersteOption.Attribute("value").Value = "77";					


Ich hoffe das hilft dir weiter,

Gruß
Flop Threadstarter
Hält's aus hier
Beiträge: 12



BeitragVerfasst: Di 27.04.10 08:50 
Super , das sieht ja schonmal echt gut aus. Werd das gleich mal nach der schule ausprobieren ! :)

Aber was meinst du mit , dass das ersatzen analog erfolgt ? Kann Der "Benutzer" meiner tools nicht einfach in die Textbox gehen und dann sein eingetragenen wert abspeichern ? Sowas wie Ein button und dann TextBox1.Text = SaveXmlDocument ... Die vorhandene XML datei sollte dann natürlich überschrieben werden und keine neue erzeugen.

MfG
danielf
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 1012
Erhaltene Danke: 24

Windows XP
C#, Visual Studio
BeitragVerfasst: Di 27.04.10 09:50 
Ich meinte damit dass du mit XElement.Attribute(<name>).Value den Attributwert eines Element lesen und setzen kann. Je nachdem ob bei der Zuweisung der Ausdruck links oder rechts steht.