Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6049063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:32:01+00:00 2026-05-23T07:32:01+00:00

My XML File: <?xml version=1.0 encoding=utf-8?> <SimpleKD> <player name=Tardis> <kills>0</kills> <deaths>0</deaths> </player> </SimpleKD> First

  • 0

My XML File:

<?xml version="1.0" encoding="utf-8"?>
<SimpleKD>
  <player name="Tardis">
    <kills>0</kills>
    <deaths>0</deaths>
    </player>
</SimpleKD>

First off, I need to check if the username “Tardis” exists in the xml .element("player").attribute("name").

If it doesn’t, i need to create it with kills and deaths at zero.
If it does, I need to read kills and deaths and set them to variables.

I have been using XElement to try and do this.. Thanks!

Code used to write the XML:

public static string username = "Tardis";
public static int kills = 0;
public static int deaths = 0;

........

XElement Players = new XElement(
                      "SimpleKD",
                      new XElement("player",
                          new XAttribute("name", username),
                      new XElement("kills", kills),
                      new XElement("deaths", deaths)));
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T07:32:01+00:00Added an answer on May 23, 2026 at 7:32 am

    Assuming you have a Player class:

    private static Player GetPlayer(string name, XElement simpleKD)
    {
        var playerElem = simpleKD.Elements("player")
                                 .SingleOrDefault(p => p.Attribute("name").Value == name);
        if (playerElem == null)
        {
            simpleKD.Add(new XElement("player",
                                      new XAttribute("name", name),
                                      new XElement("kills", 0),
                                      new XElement("deaths", 0)));
            return new Player(name);
        }
    
        return new Player(name,
                          (int)playerElem.Element("kills"),
                          (int)playerElem.Element("deaths"));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that looks like <?xml version='1.0' encoding='UTF-8'?> <root> <node name=foo1
I created an App.config file in my WPF application: <?xml version="1.0" encoding="utf-8" ?> <configuration>
The 1.0.0.0 version of my Feature's Template.xml file looked like this: <?xml version=1.0 encoding=utf-8
have an xml file like this. <?xml version =1.0 encoding =utf-8?> <menu> <menuNode title=Register
I have an options_menu.xml file like this: <?xml version=1.0 encoding=utf-8?> <menu xmlns:android=http://schemas.android.com/apk/res/android> <item android:id=@+id/search
assuming I got following XML file : <?xml version=1.0 encoding=ISO-8859-1 ?> <MyCarShop> <Car gender=Boy>
I have an XML attribute representing the version numbering of a file. The file
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I'm trying to query an xml file using the following xslt: <xsl:stylesheet version=1.0 xmlns:xsl=http://www.w3.org/1999/XSL/Transform
I need to generate an xml file in Java, so I chose to use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.