2014-12-02 5 views
0

XML이 대소 문자를 구분한다고 생각합니까? XML 파일에서 < Header> 또는 < header> 필드를 찾으려고합니다. 나는 다음과 같은 코드를 사용합니다 XDocument.Descendents는 대소 문자를 구분하지 않습니다

If Not xmlDoc.Descendants("Header") Is Nothing Then 
    do something 
ElseIf Not xmlDoc.Descendants("header") Is Nothing Then 
    do something else 
Else 
    Print(1, "No header information found" & vbCrLf) 
    messageText.Text = "Validation Complete" 
    Return false 
End If 

그래서 내가 < 헤더가 XML 파일에서 찾고 있어요>를하고 '뭔가를'라인은 실행중인! 어떻게 대소 문자를 구분할 수 있습니까?

답변

0

XDocument.Descendants는 대소 문자를 구분되지만 정합 소자가 없다고 판단 된 경우는 Nothing를 반환하지 -이없는 요소와 IEnumerable(Of XElement)를 반환한다. 그래서, 당신은이 같은 논리 뭔가를 다시 작성할 수 :

If xmlDoc.Descendants("Header").Any() Then 
    ' do something - <Header> found 
ElseIf xmlDoc.Descendants("header").Any() Then 
    ' do something else - <header> found 
Else 
    Print(1, "No header information found" & vbCrLf) 
    messageText.Text = "Validation Complete" 
    Return false 
End If 

또한 내가 좀 더 읽을 찾을 XML 리터럴에 대한 VB.NET의 지원 사용할 수 있습니다

If xmlDoc...<Header>.Any() Then 
    ' do something - <Header> found 
ElseIf xmlDoc...<header>.Any() Then 
    ' do something else - <header> found 
Else 
    '... 
End If 
관련 문제