multiply values in xml file via c# forrm app












0















I want to make an XML editor for a game in c#.
I've got a c# forms app ready, but i need to figure out how to multiply values in the selected xml file.



The XML looks like this:



<missions>
<mission type="harvest" reward="2862" status="0" success="false">
<field id="27" sprayFactor="0.000000" spraySet="false" plowFactor="0.000000" state="2" vehicleGroup="3" vehicleUseCost="520.447510" growthState="7" limeFactor="1.000000" weedFactor="1.000000" fruitTypeName="SOYBEAN"/>
<harvest sellPoint="12" expectedLiters="10539.061523" depositedLiters="0.000000"/>
</mission>
<mission type="harvest" reward="2699" status="0" success="false">
<field id="4" sprayFactor="0.500000" spraySet="false" plowFactor="0.000000" state="2" vehicleGroup="11" vehicleUseCost="490.897491" growthState="6" limeFactor="1.000000" weedFactor="1.000000" fruitTypeName="COTTON"/>
<harvest sellPoint="17" expectedLiters="13012.056641" depositedLiters="0.000000"/>
</mission>
<mission type="harvest" reward="8620" status="0" success="false">
<field id="6" sprayFactor="1.000000" spraySet="false" plowFactor="1.000000" state="2" vehicleGroup="8" vehicleUseCost="1567.417480" growthState="5" limeFactor="1.000000" weedFactor="1.000000" fruitTypeName="SUNFLOWER"/>
<harvest sellPoint="12" expectedLiters="54337.136719" depositedLiters="0.000000"/>
</mission>
<mission type="transport" reward="307" status="0" success="false" timeLeft="114865506" config="WATER" pickupTrigger="TRANSPORT04" dropoffTrigger="TRANSPORT01" objectFilename="data/objects/pallets/missions/transportPalletBottles.i3d" numObjects="1"/>




I want to multiply all the values reward="xxxxx"



My c# code looks like this:



 public Form1()
{
InitializeComponent();
CenterToScreen();
string multiply = textBox1.Text;
}

XmlDocument missions;
string path;
private string lang;

public void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
{
lang = "en";
}
}

public void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
lang = "nl";
}
}

public void button2_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string strfilelocation = openFileDialog1.FileName;
textBox2.Text = strfilelocation;
path = strfilelocation;
missions = new XmlDocument();
missions.Load(path);
}
}

public void button4_Click(object sender, EventArgs e)
{
if (lang == "en")
{
MessageBox.Show("This tool is developed to make the wages of the contractjobs higher, thus giving you more money when you complete them. Select the desired percentage wich you want the program to multiply the wages with, and select the missions.xml in your desired savegame. Click apply, and then save. You need to run this program every once in a while, to update the wages, or use it once and copy the file. (disclaimer: when you have raised wages, and you run teh program again, and jobs with raised wages are still in missions.xml, the wages will get even higher then is was.)");
} else if (lang == "nl")
{
MessageBox.Show("This tool is developed to make the wages of the contractjobs higher, thus giving you more money when you complete them. Select the desired percentage wich you want the program to multiply the wages with, and select the missions.xml in your desired savegame. Click apply, and then save. You need to run this program every once in a while, to update the wages, or use it once and copy the file. (disclaimer: when you have raised wages, and you run teh program again, and jobs with raised wages are still in missions.xml, the wages will get even higher then is was.)");
}
}


Is there an easy way to do this? If yes, can someone point me in the direction? I'm not asking for all the code, just a little startup, because i'm stuck at this point.



Thanks in advance!



///////////////////////////////////////////
New error;



System.Xml.XmlException: 'Data at the root level is invalid. Line 1, position 1.'



code:



var text = path;

var xml = XElement.Parse(text);
var rewards = xml
.Descendants()
.Where(d => d.Attribute("reward") != null)
.Select(d => d.Attribute("reward"));
// Do something with rewards. For instance, displaying them in the console
rewards.ToList().ForEach(r => Console.WriteLine(r.Value));









share|improve this question

























  • I.e. 2862*2699*8620*307?

    – JohnyL
    Nov 22 '18 at 17:14











  • No, textbox 1 gives a number, wich represents a percentage, So it would be like this: 2862100*{textbox1 value}+2862 = ... and than that for every reward entry.

    – Justin Rijsdijk
    Nov 22 '18 at 17:20


















0















I want to make an XML editor for a game in c#.
I've got a c# forms app ready, but i need to figure out how to multiply values in the selected xml file.



The XML looks like this:



<missions>
<mission type="harvest" reward="2862" status="0" success="false">
<field id="27" sprayFactor="0.000000" spraySet="false" plowFactor="0.000000" state="2" vehicleGroup="3" vehicleUseCost="520.447510" growthState="7" limeFactor="1.000000" weedFactor="1.000000" fruitTypeName="SOYBEAN"/>
<harvest sellPoint="12" expectedLiters="10539.061523" depositedLiters="0.000000"/>
</mission>
<mission type="harvest" reward="2699" status="0" success="false">
<field id="4" sprayFactor="0.500000" spraySet="false" plowFactor="0.000000" state="2" vehicleGroup="11" vehicleUseCost="490.897491" growthState="6" limeFactor="1.000000" weedFactor="1.000000" fruitTypeName="COTTON"/>
<harvest sellPoint="17" expectedLiters="13012.056641" depositedLiters="0.000000"/>
</mission>
<mission type="harvest" reward="8620" status="0" success="false">
<field id="6" sprayFactor="1.000000" spraySet="false" plowFactor="1.000000" state="2" vehicleGroup="8" vehicleUseCost="1567.417480" growthState="5" limeFactor="1.000000" weedFactor="1.000000" fruitTypeName="SUNFLOWER"/>
<harvest sellPoint="12" expectedLiters="54337.136719" depositedLiters="0.000000"/>
</mission>
<mission type="transport" reward="307" status="0" success="false" timeLeft="114865506" config="WATER" pickupTrigger="TRANSPORT04" dropoffTrigger="TRANSPORT01" objectFilename="data/objects/pallets/missions/transportPalletBottles.i3d" numObjects="1"/>




I want to multiply all the values reward="xxxxx"



My c# code looks like this:



 public Form1()
{
InitializeComponent();
CenterToScreen();
string multiply = textBox1.Text;
}

XmlDocument missions;
string path;
private string lang;

public void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
{
lang = "en";
}
}

public void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
lang = "nl";
}
}

public void button2_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string strfilelocation = openFileDialog1.FileName;
textBox2.Text = strfilelocation;
path = strfilelocation;
missions = new XmlDocument();
missions.Load(path);
}
}

public void button4_Click(object sender, EventArgs e)
{
if (lang == "en")
{
MessageBox.Show("This tool is developed to make the wages of the contractjobs higher, thus giving you more money when you complete them. Select the desired percentage wich you want the program to multiply the wages with, and select the missions.xml in your desired savegame. Click apply, and then save. You need to run this program every once in a while, to update the wages, or use it once and copy the file. (disclaimer: when you have raised wages, and you run teh program again, and jobs with raised wages are still in missions.xml, the wages will get even higher then is was.)");
} else if (lang == "nl")
{
MessageBox.Show("This tool is developed to make the wages of the contractjobs higher, thus giving you more money when you complete them. Select the desired percentage wich you want the program to multiply the wages with, and select the missions.xml in your desired savegame. Click apply, and then save. You need to run this program every once in a while, to update the wages, or use it once and copy the file. (disclaimer: when you have raised wages, and you run teh program again, and jobs with raised wages are still in missions.xml, the wages will get even higher then is was.)");
}
}


Is there an easy way to do this? If yes, can someone point me in the direction? I'm not asking for all the code, just a little startup, because i'm stuck at this point.



Thanks in advance!



///////////////////////////////////////////
New error;



System.Xml.XmlException: 'Data at the root level is invalid. Line 1, position 1.'



code:



var text = path;

var xml = XElement.Parse(text);
var rewards = xml
.Descendants()
.Where(d => d.Attribute("reward") != null)
.Select(d => d.Attribute("reward"));
// Do something with rewards. For instance, displaying them in the console
rewards.ToList().ForEach(r => Console.WriteLine(r.Value));









share|improve this question

























  • I.e. 2862*2699*8620*307?

    – JohnyL
    Nov 22 '18 at 17:14











  • No, textbox 1 gives a number, wich represents a percentage, So it would be like this: 2862100*{textbox1 value}+2862 = ... and than that for every reward entry.

    – Justin Rijsdijk
    Nov 22 '18 at 17:20
















0












0








0








I want to make an XML editor for a game in c#.
I've got a c# forms app ready, but i need to figure out how to multiply values in the selected xml file.



The XML looks like this:



<missions>
<mission type="harvest" reward="2862" status="0" success="false">
<field id="27" sprayFactor="0.000000" spraySet="false" plowFactor="0.000000" state="2" vehicleGroup="3" vehicleUseCost="520.447510" growthState="7" limeFactor="1.000000" weedFactor="1.000000" fruitTypeName="SOYBEAN"/>
<harvest sellPoint="12" expectedLiters="10539.061523" depositedLiters="0.000000"/>
</mission>
<mission type="harvest" reward="2699" status="0" success="false">
<field id="4" sprayFactor="0.500000" spraySet="false" plowFactor="0.000000" state="2" vehicleGroup="11" vehicleUseCost="490.897491" growthState="6" limeFactor="1.000000" weedFactor="1.000000" fruitTypeName="COTTON"/>
<harvest sellPoint="17" expectedLiters="13012.056641" depositedLiters="0.000000"/>
</mission>
<mission type="harvest" reward="8620" status="0" success="false">
<field id="6" sprayFactor="1.000000" spraySet="false" plowFactor="1.000000" state="2" vehicleGroup="8" vehicleUseCost="1567.417480" growthState="5" limeFactor="1.000000" weedFactor="1.000000" fruitTypeName="SUNFLOWER"/>
<harvest sellPoint="12" expectedLiters="54337.136719" depositedLiters="0.000000"/>
</mission>
<mission type="transport" reward="307" status="0" success="false" timeLeft="114865506" config="WATER" pickupTrigger="TRANSPORT04" dropoffTrigger="TRANSPORT01" objectFilename="data/objects/pallets/missions/transportPalletBottles.i3d" numObjects="1"/>




I want to multiply all the values reward="xxxxx"



My c# code looks like this:



 public Form1()
{
InitializeComponent();
CenterToScreen();
string multiply = textBox1.Text;
}

XmlDocument missions;
string path;
private string lang;

public void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
{
lang = "en";
}
}

public void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
lang = "nl";
}
}

public void button2_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string strfilelocation = openFileDialog1.FileName;
textBox2.Text = strfilelocation;
path = strfilelocation;
missions = new XmlDocument();
missions.Load(path);
}
}

public void button4_Click(object sender, EventArgs e)
{
if (lang == "en")
{
MessageBox.Show("This tool is developed to make the wages of the contractjobs higher, thus giving you more money when you complete them. Select the desired percentage wich you want the program to multiply the wages with, and select the missions.xml in your desired savegame. Click apply, and then save. You need to run this program every once in a while, to update the wages, or use it once and copy the file. (disclaimer: when you have raised wages, and you run teh program again, and jobs with raised wages are still in missions.xml, the wages will get even higher then is was.)");
} else if (lang == "nl")
{
MessageBox.Show("This tool is developed to make the wages of the contractjobs higher, thus giving you more money when you complete them. Select the desired percentage wich you want the program to multiply the wages with, and select the missions.xml in your desired savegame. Click apply, and then save. You need to run this program every once in a while, to update the wages, or use it once and copy the file. (disclaimer: when you have raised wages, and you run teh program again, and jobs with raised wages are still in missions.xml, the wages will get even higher then is was.)");
}
}


Is there an easy way to do this? If yes, can someone point me in the direction? I'm not asking for all the code, just a little startup, because i'm stuck at this point.



Thanks in advance!



///////////////////////////////////////////
New error;



System.Xml.XmlException: 'Data at the root level is invalid. Line 1, position 1.'



code:



var text = path;

var xml = XElement.Parse(text);
var rewards = xml
.Descendants()
.Where(d => d.Attribute("reward") != null)
.Select(d => d.Attribute("reward"));
// Do something with rewards. For instance, displaying them in the console
rewards.ToList().ForEach(r => Console.WriteLine(r.Value));









share|improve this question
















I want to make an XML editor for a game in c#.
I've got a c# forms app ready, but i need to figure out how to multiply values in the selected xml file.



The XML looks like this:



<missions>
<mission type="harvest" reward="2862" status="0" success="false">
<field id="27" sprayFactor="0.000000" spraySet="false" plowFactor="0.000000" state="2" vehicleGroup="3" vehicleUseCost="520.447510" growthState="7" limeFactor="1.000000" weedFactor="1.000000" fruitTypeName="SOYBEAN"/>
<harvest sellPoint="12" expectedLiters="10539.061523" depositedLiters="0.000000"/>
</mission>
<mission type="harvest" reward="2699" status="0" success="false">
<field id="4" sprayFactor="0.500000" spraySet="false" plowFactor="0.000000" state="2" vehicleGroup="11" vehicleUseCost="490.897491" growthState="6" limeFactor="1.000000" weedFactor="1.000000" fruitTypeName="COTTON"/>
<harvest sellPoint="17" expectedLiters="13012.056641" depositedLiters="0.000000"/>
</mission>
<mission type="harvest" reward="8620" status="0" success="false">
<field id="6" sprayFactor="1.000000" spraySet="false" plowFactor="1.000000" state="2" vehicleGroup="8" vehicleUseCost="1567.417480" growthState="5" limeFactor="1.000000" weedFactor="1.000000" fruitTypeName="SUNFLOWER"/>
<harvest sellPoint="12" expectedLiters="54337.136719" depositedLiters="0.000000"/>
</mission>
<mission type="transport" reward="307" status="0" success="false" timeLeft="114865506" config="WATER" pickupTrigger="TRANSPORT04" dropoffTrigger="TRANSPORT01" objectFilename="data/objects/pallets/missions/transportPalletBottles.i3d" numObjects="1"/>




I want to multiply all the values reward="xxxxx"



My c# code looks like this:



 public Form1()
{
InitializeComponent();
CenterToScreen();
string multiply = textBox1.Text;
}

XmlDocument missions;
string path;
private string lang;

public void radioButton2_CheckedChanged(object sender, EventArgs e)
{
if (radioButton2.Checked == true)
{
lang = "en";
}
}

public void radioButton1_CheckedChanged(object sender, EventArgs e)
{
if (radioButton1.Checked == true)
{
lang = "nl";
}
}

public void button2_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
string strfilelocation = openFileDialog1.FileName;
textBox2.Text = strfilelocation;
path = strfilelocation;
missions = new XmlDocument();
missions.Load(path);
}
}

public void button4_Click(object sender, EventArgs e)
{
if (lang == "en")
{
MessageBox.Show("This tool is developed to make the wages of the contractjobs higher, thus giving you more money when you complete them. Select the desired percentage wich you want the program to multiply the wages with, and select the missions.xml in your desired savegame. Click apply, and then save. You need to run this program every once in a while, to update the wages, or use it once and copy the file. (disclaimer: when you have raised wages, and you run teh program again, and jobs with raised wages are still in missions.xml, the wages will get even higher then is was.)");
} else if (lang == "nl")
{
MessageBox.Show("This tool is developed to make the wages of the contractjobs higher, thus giving you more money when you complete them. Select the desired percentage wich you want the program to multiply the wages with, and select the missions.xml in your desired savegame. Click apply, and then save. You need to run this program every once in a while, to update the wages, or use it once and copy the file. (disclaimer: when you have raised wages, and you run teh program again, and jobs with raised wages are still in missions.xml, the wages will get even higher then is was.)");
}
}


Is there an easy way to do this? If yes, can someone point me in the direction? I'm not asking for all the code, just a little startup, because i'm stuck at this point.



Thanks in advance!



///////////////////////////////////////////
New error;



System.Xml.XmlException: 'Data at the root level is invalid. Line 1, position 1.'



code:



var text = path;

var xml = XElement.Parse(text);
var rewards = xml
.Descendants()
.Where(d => d.Attribute("reward") != null)
.Select(d => d.Attribute("reward"));
// Do something with rewards. For instance, displaying them in the console
rewards.ToList().ForEach(r => Console.WriteLine(r.Value));






c# winforms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 18:56







Justin Rijsdijk

















asked Nov 22 '18 at 17:07









Justin RijsdijkJustin Rijsdijk

33




33













  • I.e. 2862*2699*8620*307?

    – JohnyL
    Nov 22 '18 at 17:14











  • No, textbox 1 gives a number, wich represents a percentage, So it would be like this: 2862100*{textbox1 value}+2862 = ... and than that for every reward entry.

    – Justin Rijsdijk
    Nov 22 '18 at 17:20





















  • I.e. 2862*2699*8620*307?

    – JohnyL
    Nov 22 '18 at 17:14











  • No, textbox 1 gives a number, wich represents a percentage, So it would be like this: 2862100*{textbox1 value}+2862 = ... and than that for every reward entry.

    – Justin Rijsdijk
    Nov 22 '18 at 17:20



















I.e. 2862*2699*8620*307?

– JohnyL
Nov 22 '18 at 17:14





I.e. 2862*2699*8620*307?

– JohnyL
Nov 22 '18 at 17:14













No, textbox 1 gives a number, wich represents a percentage, So it would be like this: 2862100*{textbox1 value}+2862 = ... and than that for every reward entry.

– Justin Rijsdijk
Nov 22 '18 at 17:20







No, textbox 1 gives a number, wich represents a percentage, So it would be like this: 2862100*{textbox1 value}+2862 = ... and than that for every reward entry.

– Justin Rijsdijk
Nov 22 '18 at 17:20














1 Answer
1






active

oldest

votes


















0














I have stripped down XML a bit to omit text we don't need. The code extracts all rewards. You can do with them whatever you need:



var text = @"
<missions>
<mission type='harvest' reward='2862' status='0' success='false'>
</mission>
<mission type='harvest' reward='2699' status='0' success='false'>
</mission>
<mission type='harvest' reward='8620' status='0' success='false'>
</mission>
<mission type='transport' reward='307' status='0' success='false' />
</missions>";

var xml = XElement.Parse(text);
var rewards = xml
.Descendants()
.Where(d => d.Attribute("reward") != null)
.Select(d => d.Attribute("reward"));
// Do something with rewards. For instance, displaying them in the console
rewards.ToList().ForEach(r => Console.WriteLine(r.Value));





share|improve this answer
























  • Thanks, will look into it when im done eating!

    – Justin Rijsdijk
    Nov 22 '18 at 17:45











  • @JustinRijsdijk Good appetite! 😉

    – JohnyL
    Nov 22 '18 at 18:11











  • So how would I fill te var text you've created with dynamic data? the form loads the xml file by an OFD, so I want that info to fill the text var. || Thanks @JohnyL

    – Justin Rijsdijk
    Nov 22 '18 at 18:19













  • @JustinRijsdijk OFD - Open File Dialog? Am I right?

    – JohnyL
    Nov 22 '18 at 18:39











  • Yes, open File Dialog! @JohnyL

    – Justin Rijsdijk
    Nov 22 '18 at 18:42











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435605%2fmultiply-values-in-xml-file-via-c-sharp-forrm-app%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I have stripped down XML a bit to omit text we don't need. The code extracts all rewards. You can do with them whatever you need:



var text = @"
<missions>
<mission type='harvest' reward='2862' status='0' success='false'>
</mission>
<mission type='harvest' reward='2699' status='0' success='false'>
</mission>
<mission type='harvest' reward='8620' status='0' success='false'>
</mission>
<mission type='transport' reward='307' status='0' success='false' />
</missions>";

var xml = XElement.Parse(text);
var rewards = xml
.Descendants()
.Where(d => d.Attribute("reward") != null)
.Select(d => d.Attribute("reward"));
// Do something with rewards. For instance, displaying them in the console
rewards.ToList().ForEach(r => Console.WriteLine(r.Value));





share|improve this answer
























  • Thanks, will look into it when im done eating!

    – Justin Rijsdijk
    Nov 22 '18 at 17:45











  • @JustinRijsdijk Good appetite! 😉

    – JohnyL
    Nov 22 '18 at 18:11











  • So how would I fill te var text you've created with dynamic data? the form loads the xml file by an OFD, so I want that info to fill the text var. || Thanks @JohnyL

    – Justin Rijsdijk
    Nov 22 '18 at 18:19













  • @JustinRijsdijk OFD - Open File Dialog? Am I right?

    – JohnyL
    Nov 22 '18 at 18:39











  • Yes, open File Dialog! @JohnyL

    – Justin Rijsdijk
    Nov 22 '18 at 18:42
















0














I have stripped down XML a bit to omit text we don't need. The code extracts all rewards. You can do with them whatever you need:



var text = @"
<missions>
<mission type='harvest' reward='2862' status='0' success='false'>
</mission>
<mission type='harvest' reward='2699' status='0' success='false'>
</mission>
<mission type='harvest' reward='8620' status='0' success='false'>
</mission>
<mission type='transport' reward='307' status='0' success='false' />
</missions>";

var xml = XElement.Parse(text);
var rewards = xml
.Descendants()
.Where(d => d.Attribute("reward") != null)
.Select(d => d.Attribute("reward"));
// Do something with rewards. For instance, displaying them in the console
rewards.ToList().ForEach(r => Console.WriteLine(r.Value));





share|improve this answer
























  • Thanks, will look into it when im done eating!

    – Justin Rijsdijk
    Nov 22 '18 at 17:45











  • @JustinRijsdijk Good appetite! 😉

    – JohnyL
    Nov 22 '18 at 18:11











  • So how would I fill te var text you've created with dynamic data? the form loads the xml file by an OFD, so I want that info to fill the text var. || Thanks @JohnyL

    – Justin Rijsdijk
    Nov 22 '18 at 18:19













  • @JustinRijsdijk OFD - Open File Dialog? Am I right?

    – JohnyL
    Nov 22 '18 at 18:39











  • Yes, open File Dialog! @JohnyL

    – Justin Rijsdijk
    Nov 22 '18 at 18:42














0












0








0







I have stripped down XML a bit to omit text we don't need. The code extracts all rewards. You can do with them whatever you need:



var text = @"
<missions>
<mission type='harvest' reward='2862' status='0' success='false'>
</mission>
<mission type='harvest' reward='2699' status='0' success='false'>
</mission>
<mission type='harvest' reward='8620' status='0' success='false'>
</mission>
<mission type='transport' reward='307' status='0' success='false' />
</missions>";

var xml = XElement.Parse(text);
var rewards = xml
.Descendants()
.Where(d => d.Attribute("reward") != null)
.Select(d => d.Attribute("reward"));
// Do something with rewards. For instance, displaying them in the console
rewards.ToList().ForEach(r => Console.WriteLine(r.Value));





share|improve this answer













I have stripped down XML a bit to omit text we don't need. The code extracts all rewards. You can do with them whatever you need:



var text = @"
<missions>
<mission type='harvest' reward='2862' status='0' success='false'>
</mission>
<mission type='harvest' reward='2699' status='0' success='false'>
</mission>
<mission type='harvest' reward='8620' status='0' success='false'>
</mission>
<mission type='transport' reward='307' status='0' success='false' />
</missions>";

var xml = XElement.Parse(text);
var rewards = xml
.Descendants()
.Where(d => d.Attribute("reward") != null)
.Select(d => d.Attribute("reward"));
// Do something with rewards. For instance, displaying them in the console
rewards.ToList().ForEach(r => Console.WriteLine(r.Value));






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 '18 at 17:26









JohnyLJohnyL

3,6581923




3,6581923













  • Thanks, will look into it when im done eating!

    – Justin Rijsdijk
    Nov 22 '18 at 17:45











  • @JustinRijsdijk Good appetite! 😉

    – JohnyL
    Nov 22 '18 at 18:11











  • So how would I fill te var text you've created with dynamic data? the form loads the xml file by an OFD, so I want that info to fill the text var. || Thanks @JohnyL

    – Justin Rijsdijk
    Nov 22 '18 at 18:19













  • @JustinRijsdijk OFD - Open File Dialog? Am I right?

    – JohnyL
    Nov 22 '18 at 18:39











  • Yes, open File Dialog! @JohnyL

    – Justin Rijsdijk
    Nov 22 '18 at 18:42



















  • Thanks, will look into it when im done eating!

    – Justin Rijsdijk
    Nov 22 '18 at 17:45











  • @JustinRijsdijk Good appetite! 😉

    – JohnyL
    Nov 22 '18 at 18:11











  • So how would I fill te var text you've created with dynamic data? the form loads the xml file by an OFD, so I want that info to fill the text var. || Thanks @JohnyL

    – Justin Rijsdijk
    Nov 22 '18 at 18:19













  • @JustinRijsdijk OFD - Open File Dialog? Am I right?

    – JohnyL
    Nov 22 '18 at 18:39











  • Yes, open File Dialog! @JohnyL

    – Justin Rijsdijk
    Nov 22 '18 at 18:42

















Thanks, will look into it when im done eating!

– Justin Rijsdijk
Nov 22 '18 at 17:45





Thanks, will look into it when im done eating!

– Justin Rijsdijk
Nov 22 '18 at 17:45













@JustinRijsdijk Good appetite! 😉

– JohnyL
Nov 22 '18 at 18:11





@JustinRijsdijk Good appetite! 😉

– JohnyL
Nov 22 '18 at 18:11













So how would I fill te var text you've created with dynamic data? the form loads the xml file by an OFD, so I want that info to fill the text var. || Thanks @JohnyL

– Justin Rijsdijk
Nov 22 '18 at 18:19







So how would I fill te var text you've created with dynamic data? the form loads the xml file by an OFD, so I want that info to fill the text var. || Thanks @JohnyL

– Justin Rijsdijk
Nov 22 '18 at 18:19















@JustinRijsdijk OFD - Open File Dialog? Am I right?

– JohnyL
Nov 22 '18 at 18:39





@JustinRijsdijk OFD - Open File Dialog? Am I right?

– JohnyL
Nov 22 '18 at 18:39













Yes, open File Dialog! @JohnyL

– Justin Rijsdijk
Nov 22 '18 at 18:42





Yes, open File Dialog! @JohnyL

– Justin Rijsdijk
Nov 22 '18 at 18:42


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435605%2fmultiply-values-in-xml-file-via-c-sharp-forrm-app%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

404 Error Contact Form 7 ajax form submitting

How to know if a Active Directory user can login interactively

TypeError: fit_transform() missing 1 required positional argument: 'X'