What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

[C#/XML] Writing Multiple Values in an Element

Smarter

Member
Joined
Jan 15, 2010
Messages
763
Reaction score
9
Okay, I have never been good with anything involving IO/XML ... for the life of me I cannot figure out how to write multiple values into an Element, suchas:
PHP:
<Mob Name="Blah" Entry="1234" />
XmlWriter.WriteElementString(); - Writes
PHP:
<Mob>Blah</Mob>
.... :-\. Someone want to point me in the write direction? :-\
 
Thank you very much, however this creates a full ended element. I need one simply
PHP:
<Mob Blah=123" />
I.e HB Format "/>".
 
Last edited:
have you looked at Mr.GearBuyer? it uses a save method like that, you might be able to learn from it.
 
have you looked at Mr.GearBuyer? it uses a save method like that, you might be able to learn from it.
Code:
            public XElement ToXml()
            {
                return new XElement(
                            "Item",
                            new XElement("ItemId", ItemId),
                            new XElement("ItemName", ItemName),
                            new XElement("ItemCost", ItemCost),
                            new XElement("ItemCostType", ItemCostType),
                            new XElement("ItemSupplierId", ItemSupplierId)
                            );
            }
This is the method you speak of?
 
I suggest using LINQ to XML (or just XElement/XAttribute/etc)

Code:
new XElement("Mob", new XAttribute("Entry", mobEntry)).ToString()

Play around with it. It makes life much simpler.
 
Code:
            public XElement ToXml()
            {
                return new XElement(
                            "Item",
                            new XElement("ItemId", ItemId),
                            new XElement("ItemName", ItemName),
                            new XElement("ItemCost", ItemCost),
                            new XElement("ItemCostType", ItemCostType),
                            new XElement("ItemSupplierId", ItemSupplierId)
                            );
            }
This is the method you speak of?
yea, i guess, or you know...just listen to apoc
 
yea, i guess, or you know...just listen to apoc
Hah, thanks, but yeah generally that's what I do :-P.

I suggest using LINQ to XML (or just XElement/XAttribute/etc)

Code:
new XElement("Mob", new XAttribute("Entry", mobEntry)).ToString()

Play around with it. It makes life much simpler.

Ah, much better, thank you very much.
 
(Double Post, I know)

Just to make sure I got this right, instead of testing it like a non-lazy person lol:
Code:
            var profileXml =
                new XElement("HBProfile",
                             new XElement("Name", profile.Name),
                             new XElement("MinLevel", profile.MinLevel.ToString()),
                             new XElement("MaxLevel", profile.MaxLevel.ToString()),
                             new XElement("MinDurability", profile.MinDurability.ToString()),
                             new XElement("MinFreeBagSlots", profile.MinFreeBagSlots.ToString()),
                             new XElement("MailGrey", profile.MailGrey.ToString()),
                             new XElement("MailWhite", profile.MailWhite.ToString()),
                             new XElement("MailGreen", profile.MailGreen.ToString()),
                             new XElement("MailBlue", profile.MailBlue.ToString()),
                             new XElement("MailPurple", profile.MailPurple.ToString()),
                             new XElement("SellGrey", profile.SellGrey.ToString()),
                             new XElement("SellWhite", profile.SellWhite.ToString()),
                             new XElement("SellGreen", profile.SellGreen.ToString()),
                             new XElement("SellBlue", profile.SellBlue.ToString()),
                             new XElement("SellPurple", profile.SellPurple.ToString()),
                             new XElement("TargetElites", profile.TargetElites.ToString()),
                             new XElement("ContinentId", profile.ContinentId.ToString()));
            profileXml.Save("someProfile.xml");

Would produce the header, (Properly?) etc?
 
Back
Top