Search code examples
c#xpathxmldocumentselectsinglenode

//@attrib vs //name/@attrib in C#


On the XML below, I'm using the SelectSingleNode of XmlDocument to pull out the result value.

evtASxml.SelectSingleNode(@"//@value").Value

returns the value of the first "value."

evtASxml.SelectSingleNode(@"//Result/@value").Value

raises a null exception.

Could someone explain what's going on?

 <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
 <System>
  <Provider Name="Microsoft-Windows-CAPI2" Guid="{f00f00-f00-f00f00-f00-f00f00f00}" /> 
  <EventID>30</EventID> 
  <Version>0</Version> 
  <Level>2</Level> 
  <Task>30</Task> 
  <Opcode>0</Opcode> 
  <Keywords>0x4000000000000001</Keywords> 
  <TimeCreated SystemTime="2012-04-08T23:43:37.573242200Z" /> 
  <EventRecordID>4828</EventRecordID> 
  <Correlation ActivityID="{f00f00-f00-f00-f00-f00f00f00f00}" /> 
  <Execution ProcessID="7512" ThreadID="3220" /> 
  <Channel>Microsoft-Windows-CAPI2/Operational</Channel> 
  <Computer>Matt-Seven</Computer> 
  <Security UserID="S-f00-f00-f00-f00f00f00-f00f00f00-f00f00f00-f00f00" /> 
  </System>
 <UserData>
 <CertVerifyCertificateChainPolicy>
  <Policy type="CERT_CHAIN_POLICY_SSL" constant="4" /> 
  <Certificate fileRef="f00f00f00f00f00f00f00f00f00f00f00.cer" subjectName="www.example.com" /> 
  <CertificateChain chainRef="{f00f00-f00-f00-f00-f00f00f00f00}" /> 
  <Flags value="0" /> 
 <SSLAdditionalPolicyInfo authType="server" serverName="example.com">
  <IgnoreFlags value="0" /> 
  </SSLAdditionalPolicyInfo>
  <Status chainIndex="0" elementIndex="0" /> 
  <EventAuxInfo ProcessName="iexplore.exe" /> 
  <CorrelationAuxInfo TaskId="{f00f00-f00-f00-f00-f00f00f00f00}" SeqNumber="4" /> 
  <Result value="800B010F">The certificate's CN name does not match the passed value.</Result> 
  </CertVerifyCertificateChainPolicy>
  </UserData>
  </Event>

Numeric values from my event log replaced with f00.


Solution

  • Just guessing, but I think you want //*[@value], and not //@value

    enter image description here