How to write XPATH with conditions,

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ajayvaram
    New Member
    • Dec 2007
    • 14

    How to write XPATH with conditions,

    <?xml version="1.0" encoding="utf-8"?>
    <CategoryList >
    <Category ID="01" Title="One">
    </Category>
    <Category ID="03" Title="Three">
    </Category>
    <Category ID="04" Title="Four">
    <Style Color="Red" >
    <Car Name="R"/>
    </Style>
    <Style Color="Blue" >
    <Car Name="B"/>
    </Style>
    <Style Color="White" >
    <Car Name="W"/>
    </Style>
    </Category>
    <Category ID="02" Title="Two">
    </Category>
    </CategoryList>


    "/CategoryList/Category[@ID=01]/Title"
    Present im using this xpath to find "Title" value where ID=01

    1? Suppose ID=01 is not( i mean 01 is not a value for ID in Xml file) available , then wt will happen and how to handle that.

    and i want write Xpath ( which includes more than 2 r 3 conditions) based on conditions

    2? suppose ID=4 and Color=Blue then i have find value for "Car" ( two conditions)then how to write XPATH for this
    * hre we hav different values for both ID & Color,

    Thanks,
    Ajay
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Originally posted by ajayvaram
    <?xml version="1.0" encoding="utf-8"?>
    <CategoryList >
    <Category ID="01" Title="One">
    </Category>
    <Category ID="03" Title="Three">
    </Category>
    <Category ID="04" Title="Four">
    <Style Color="Red" >
    <Car Name="R"/>
    </Style>
    <Style Color="Blue" >
    <Car Name="B"/>
    </Style>
    <Style Color="White" >
    <Car Name="W"/>
    </Style>
    </Category>
    <Category ID="02" Title="Two">
    </Category>
    </CategoryList>


    "/CategoryList/Category[@ID=01]/Title"
    Present im using this xpath to find "Title" value where ID=01

    1? Suppose ID=01 is not( i mean 01 is not a value for ID in Xml file) available , then wt will happen and how to handle that.

    and i want write Xpath ( which includes more than 2 r 3 conditions) based on conditions

    2? suppose ID=4 and Color=Blue then i have find value for "Car" ( two conditions)then how to write XPATH for this
    * hre we hav different values for both ID & Color,

    Thanks,
    Ajay
    Are you trying to do this using VB 6.0?

    Comment

    Working...