2014-05-18 1 views
3

xmlReader를 설정하고 특정 요소를 확인할 수 있지만 닫는 요소를 확인하는 방법을 찾을 수 없습니다. </perls> 태그에 대한 다른 case 문을 넣고 싶습니다. 첫 오프닝에 추가하면, 어떻게해야합니까? 나는 그러한 태그가 자기 닫히지 않는다는 것을 확실히 알고있다.xmlReader가 콘크리트 최종 요소인지 확인합니다.

using (XmlReader reader = XmlReader.Create("perls.xml")) 
{ 
    while (reader.Read()) 
    { 
    // Only detect start elements. 
    if (reader.IsStartElement()) 
    { 
     // Get element name and switch on it. 
     switch (reader.Name) 
     { 
     case "perls": 
      // Detect this element. 
      Console.WriteLine("Start <perls> element."); 
      break; 
     case "article": 
      // Detect this article element. 
      Console.WriteLine("Start <article> element."); 
      // Search for the attribute name on this current node. 
      string attribute = reader["name"]; 
      if (attribute != null) 
      { 
      Console.WriteLine(" Has attribute name: " + attribute); 
      } 
      // Next read will contain text. 
      if (reader.Read()) 
      { 
      Console.WriteLine(" Text node: " + reader.Value.Trim()); 
      } 
      break; 
     } 
    } 
    } 
} 

답변

관련 문제