none
How to read xml element is present in xml or not in expression shape RRS feed

  • Question

  • Hi All,

    I want to read xml element and then in decide shape i need to check if this element is present or not.

    Sample xml ismentioned below

     

    <ns0:ZDOM_VEH_Response xmlns:ns0="http://schemas.microsoft.com/BizTalk/2003">
    <IT_HEADER_D>
    <DEALER>1V2006</DEALER>
    </IT_HEADER_D>
    <IT_LINEITEM>
    <SP>dh45</SP>
    </IT_LINEITEM>
    
    </ns0:ZDOM_VEH_Response>
    

    I want to check in expression shape that IT_HEADER_D tag is present in xml or not

    How can i achieve this in BizTalk Orchestration.


    -- Kind Regards Sandeep
    Monday, August 22, 2011 12:36 PM

Answers

  • Hi Sandeep,

    In that case you can just use the count() function instead of string() function. Then you can check if count == 0 which means node is not present.

    Cheers,

    Bali


    --------------------------------------
    Mark As Answer or Vote As Helpful if this helps.
    • Marked as answer by Sandeep.Handa Tuesday, August 23, 2011 8:50 AM
    Tuesday, August 23, 2011 5:27 AM

All replies

  • Use XPath for getting the value of this element.

    Look at this blog post and this for a sample.

    Cheers,

    Bali


    --------------------------------------
    Mark As Answer or Vote As Helpful if this helps.
    Monday, August 22, 2011 12:58 PM
  • I think you can't do it in the decide shape it self. You need a variable and expression shape before it, where you use an Xpath to extract the value to a variable and it is this variable you use to check for in the decide shape.
    Torben Christiansen http://snatchedmoments.blogspot.com/
    Monday, August 22, 2011 8:34 PM
  • Hi,

    I tried getting value of element in variiable and then check value of variable in decide shape..please advise if below mentioned xpath is OK.

    Var1= xpath(Message_VEH_POSTSHIP,"string(/*[local-name()='ZDOM_VEH_Response']/*[local-name()='IT_HEADER_D'])");

    In rule shape :

     

    System.String.IsNullOrEmpty(Var1)

     

    But my query is IT_HEADER_D is always be empty its a parent element for elements under.

    So is checking variable in rule shape is correct.

    Pls advise

     

     

     


    -- Kind Regards Sandeep
    Tuesday, August 23, 2011 4:19 AM
  • Sandeep, 

    If you check the properties of this element in the Schema Editor in VS, you will have a property called Instance Xpath, use that in your XPath query.

    Cheers,

    Bali


    --------------------------------------
    Mark As Answer or Vote As Helpful if this helps.
    Tuesday, August 23, 2011 4:26 AM
  • Hi Bali,

    Thanks for your reply.

    Yes i am implemented the solution but only one doubt is as IT_HEADER_D is parent element so how can i check for value inside .

    As mentioned in above xml parent node won't any data.

    Pls Advise.

     


    -- Kind Regards Sandeep
    Tuesday, August 23, 2011 5:00 AM
  • Hi Sandeep,

    In that case you can just use the count() function instead of string() function. Then you can check if count == 0 which means node is not present.

    Cheers,

    Bali


    --------------------------------------
    Mark As Answer or Vote As Helpful if this helps.
    • Marked as answer by Sandeep.Handa Tuesday, August 23, 2011 8:50 AM
    Tuesday, August 23, 2011 5:27 AM
  • Hi Bali,

    Got Success using count() function inside Rule shape

    Thanks a lot..


    -- Kind Regards Sandeep
    Tuesday, August 23, 2011 8:49 AM