I don't succeed in parsing a simple xml-file

aindrea

Member
Joined
Jun 5, 2018
Messages
23
Programming Experience
1-3
I have got a simple XmlReader with the path to my xml-file ans a settings object as constructor arguments. When executing the code, the debugger always tells me that "r" does not exist in the current context. How can this be?

C#:
XmlReader r = XmlReader.Create(@"C:\Users\<me>\Desktop\test.xml", new XmlReaderSettings());
 
XmlDocument doc = new XmlDocument();
doc.Load(r);
 
When executing the code, the debugger always tells me that "r" does not exist in the current context.

Please explain EXACTLY what you mean by that. I would expect that sort of message if, for instance, you placed a watch on that variable when you break in that code and then you step out of that block. What EXACTLY are you doing and EXACTLY how does the debugger tell you that? Please don't provide vague descriptions because the more you leave to our imagination, the more likely we'll guess wrong.
 
Originally, I wanted to parse through an xml document, and I wanted to store its nodes in a list - what is more, my attempt to do so was crowned with success:


C#:
XmlNodeList elemList = doc.GetElementsByTagName("Manage");
List<Manage> mng = new List<Manage>();


...it is these nodes that I am dealing with:

C#:
<Manage Content="false" BookName="">
    <Editor Active="true">Gone with the wind.pdf</Editor>
  </Manage>

Now if I have a node like this one XmlNode node = mng[2]; - how can I access all that is written within the tag, "Content="false" BookName=""" that is? Is there a getter for those?
 
Are you asking how to determine what attributes the element has and what their values are? It looks like you already have a class that corresponds to that element so do you already know what attributes there are and you just need the values? The XmlNode class has an Attributes property, so you should probably start there.
 
Back
Top Bottom