Click here to Skip to main content
15,920,602 members
Home / Discussions / C#
   

C#

 
GeneralRe: RtlSetProcessIsCritical, Marshall and pointers. Pin
Night Lol19-Jul-10 5:14
Night Lol19-Jul-10 5:14 
GeneralRe: RtlSetProcessIsCritical, Marshall and pointers. Pin
DaveyM6919-Jul-10 5:31
professionalDaveyM6919-Jul-10 5:31 
GeneralRe: RtlSetProcessIsCritical, Marshall and pointers. Pin
Night Lol19-Jul-10 5:51
Night Lol19-Jul-10 5:51 
GeneralRe: RtlSetProcessIsCritical, Marshall and pointers. Pin
DaveyM6919-Jul-10 7:46
professionalDaveyM6919-Jul-10 7:46 
AnswerRe: RtlSetProcessIsCritical, Marshall and pointers. Pin
Luc Pattyn19-Jul-10 5:33
sitebuilderLuc Pattyn19-Jul-10 5:33 
GeneralRe: RtlSetProcessIsCritical, Marshall and pointers. Pin
Night Lol19-Jul-10 5:52
Night Lol19-Jul-10 5:52 
QuestionUnable to reference shared assembly in GAC [modified] Solved Pin
Jonathan Davies19-Jul-10 2:30
Jonathan Davies19-Jul-10 2:30 
AnswerRe: Unable to reference shared assembly in GAC Pin
PIEBALDconsult19-Jul-10 3:13
mvePIEBALDconsult19-Jul-10 3:13 
GeneralRe: Unable to reference shared assembly in GAC Pin
Jonathan Davies19-Jul-10 4:02
Jonathan Davies19-Jul-10 4:02 
QuestionHTML Table tag text Scraping Pin
NaveenHS19-Jul-10 0:48
NaveenHS19-Jul-10 0:48 
AnswerRe: HTML Table tag text Scraping Pin
Luc Pattyn19-Jul-10 0:57
sitebuilderLuc Pattyn19-Jul-10 0:57 
GeneralRe: HTML Table tag text Scraping Pin
NaveenHS19-Jul-10 1:45
NaveenHS19-Jul-10 1:45 
GeneralRe: HTML Table tag text Scraping Pin
Not Active19-Jul-10 5:41
mentorNot Active19-Jul-10 5:41 
AnswerRe: HTML Table tag text Scraping Pin
ragnaroknrol19-Jul-10 4:04
ragnaroknrol19-Jul-10 4:04 
GeneralRe: HTML Table tag text Scraping Pin
Luc Pattyn19-Jul-10 4:29
sitebuilderLuc Pattyn19-Jul-10 4:29 
AnswerRe: HTML Table tag text Scraping Pin
PIEBALDconsult19-Jul-10 4:21
mvePIEBALDconsult19-Jul-10 4:21 
QuestionReading user/group of your local machine Pin
dabuskol19-Jul-10 0:39
dabuskol19-Jul-10 0:39 
QuestionHi Pin
KORCARI18-Jul-10 23:27
KORCARI18-Jul-10 23:27 
AnswerRe: Hi Pin
Mycroft Holmes19-Jul-10 2:57
professionalMycroft Holmes19-Jul-10 2:57 
GeneralRe: Hi Pin
KORCARI19-Jul-10 3:19
KORCARI19-Jul-10 3:19 
QuestionSending XML over a Socket connection Pin
Priya Prk18-Jul-10 22:53
Priya Prk18-Jul-10 22:53 
AnswerRe: Sending XML over a Socket connection Pin
Peace ON18-Jul-10 23:08
Peace ON18-Jul-10 23:08 
QuestionRead both attributes and subtree of an XML element using XmlTextReader Pin
PPKeno18-Jul-10 22:05
PPKeno18-Jul-10 22:05 
I have an xml file that looks like this:
<root>
  <element1 />
  <element2 attr1="text" attr2="text">
    <subelement21>
      <subsubelement attr1="text" attr2="text" />
      <subsubelement attr1="text" attr2="text" />
      ...
      <subsubelement attr1="text" attr2="text" />
    </subelement21>
  </element2>
</root>


I am trying to read this file using a XmlReader. This is what I've tried but failed:

XmlTextReader reader = new XmlTextReader("file.xml");
while(reader.Read()) {
  if (reader.NodeType == XmlNodeType.Element) {
    switch (reader.Name) {
      case "element1":
        break;
      case "element2":
        reader.MoveToAttribute("attr1");
        String att1 = reader.Value;
        reader.MoveToAttribute("attr2");
        String att2 = reader.Value;
        
        XmlReader subreader = reader.ReadSubTree();
        while(subreader.Read()) {
          if(subreader.NodeType == XmlNodeType.Element) {
            switch (reader.Name) {
              case "subsubelement":
                subreader.MoveToAttribute("attr1");
                String a1 = reader.Value;
                subreader.MoveToAttribute("attr2");
                String a2 = reader.Value;
                break;
          }
        }
        break;
    }
  }
}


Here i get an exception saying that ReadSubTree() can't be called since reader is no longer at an element node, which makes sense. If I change the order and try to first read the sub tree and then the attributes of element2, i get the problem that reader is at the end element after reading the sub tree. This also makes sense, but i can't find a way to solve this.

Any ideas? I appreciate any suggestions.

Thanks
AnswerRe: Read both attributes and subtree of an XML element using XmlTextReader Pin
Peace ON18-Jul-10 22:34
Peace ON18-Jul-10 22:34 
QuestionReading .dbc file in C# Pin
Niungareamit18-Jul-10 20:14
Niungareamit18-Jul-10 20:14 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.