Summit
Summit

Reputation: 2268

How to check if a element exists in xml using xpath

This is my XMl file and I want to know if the Element "SCENE" which has has a value "SCENE_TestSene" exists.

This is my current code.

 if (xmlDoc.SelectSingleNode("//DATABASE/SCENE") == null).......

but I am not able to figure out how to check for the scene name in the xpath ?

<DATABASE>
      <SCENE SCENE_NAME="SCENE_TestSene">
        <TEMPLATE_Test>
          <Image1>C:\Temp\Pitch_Positions.jpg</Image1>
          <text1>DDASD</text1>
          <text2>ADASDSA</text2>
        </TEMPLATE_Test>
      </SCENE>
     <SCENE SCENE_NAME="SCENE_NewSene">
        <TEMPLATE_Test1>
          <Image1>C:\Temp\Pitch_Positions.jpg</Image1>
          <text1>DDASD</text1>
          <text2>ADASDSA</text2>
        </TEMPLATE_Test1>
      </SCENE>
  </DATABASE>

Upvotes: 0

Views: 1043

Answers (1)

JaSON
JaSON

Reputation: 4869

Instead of

"//DATABASE/SCENE"

try

"//DATABASE/SCENE[@SCENE_NAME='SCENE_TestSene']"

Upvotes: 1

Related Questions