Click here to Skip to main content
14,486,942 members

How do I read an XML file without it having any common tags except for attributes? (Example in problem)

antaresinsomnious asked:

Open original thread
I have been looking for the solution for the last 4 hours and have found a few pieces that help me read a standardized xml file, but doesn't allow me to read this.

I am also trying to store the parent node where "key="(not null)"" so it can't be Key="".

I am trying to pull what Key equals and the parent element from that.
I would really appreciate any help because this has been exhausting.
Thank you in advance.

	<primary device="Keyboard" key="Key_Numpad_4">
	<secondary device="{NoDevice}" key="">

	<binding device="{NoDevice}" key="">
	<inverted value="0">
	<deadzone value="0.00000000">

What I have tried:

<pre lang="C#"> XmlDocument xmlDoc = new XmlDocument();
    var edXML = GetEDBindingsPath();
    var xml = XElement.Load(edXML);

That is as far as I've gotten because everything else uses a standardized format. 
Example of what I mean by standardized...

< Users >
  < User >
    < Name > John Smith </ Name >
    < test >
      < Date > 23.05.2011 </ Date >
      < points > 33 </ points >
    </ test >
    < test >
      < Date > 22.06.2011 </ Date >
      < points > 29 </ points >
    </ test >
  </ User >
</ Users >
Tags: C#, XML, file, read


When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the The Code Project Open License (CPOL).

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100