Xpath expressions in orchestration expression shape

Hi I have a schema which is traversed using xpath expression to an element whose value is hardcoded in and being checked. Like for ex : xpath(incoming schema , "count(//Root node[normalize-space(child element)='1234xy']))

now customer wants us to add one more value to be checked for this element along with the one mentioned above. i.e. 1515xy. So I am trying to use AND operator to check for both values and return result where my exprsession looks like below.

xpath(incoming schema , "count(//Root node[normalize-space(child element)='1234xy' and '1515xy']))

or should it be like below

 xpath(incoming schema , "count(//Root node[normalize-space(child element)='1234xy'] and [normalize-space(child element)='1515xy']))

is this correct syntax? does this work? please suggest

 
August 25th, 2015 9:50am

Hi Lathaa,

Similar example discussed click here.

Quick View for xpath condition :

studentCount = 0;

if (xpath(msgStudents, "//*[local-name()='Student'][*[local-name()='sname']='John' or *[local-name()='sname']='Sam']") != null)
{
    studentCount = xpath(msgStudents, "count(//*[local-name()='Student'][*[local-name()='sname']='John' or *[local-name()='sname']='Sam'])"); 
}
// or 

xpath(msgStudents,"count(/*[local-name()='Students' and namespace-uri()='http://tempuri.org/']/*[local-name()='Student'][./*[local-name()='sname'] = 'John' or ./*[local-name()='sname'] = 'Mark'])")


Thanks. SMSVikasK

Free Windows Admin Tool Kit Click here and download it now
August 25th, 2015 10:08am

Hi Vikas, thanks for reply. Yes I think I got how I can do mine as below. Just to let you know I don't have multiple conditions but for single schema element have 2 values to be checked like below. Hope this syntax works.

 xpath(incoming schema , "count(//Root node[normalize-space(child element)='1234xy'] and [normalize-space(child element)='1515xy']))
August 25th, 2015 10:22am

I don't understand the AND?

Are you sure you don't mean OR? The way I see it, if you are talking about the same element, the AND will be impossible to meet?

Can you supply an XML example, with some Root nodes matching and some who don't?

Morten la Cour

Free Windows Admin Tool Kit Click here and download it now
August 25th, 2015 11:43am

Hi Lathaa,

Similar example discussed click here.

Quick View for xpath condition :

studentCount = 0;

if (xpath(msgStudents, "//*[local-name()='Student'][*[local-name()='sname']='John' or *[local-name()='sname']='Sam']") != null)
{
    studentCount = xpath(msgStudents, "count(//*[local-name()='Student'][*[local-name()='sname']='John' or *[local-name()='sname']='Sam'])"); 
}
// or 

xpath(msgStudents,"count(/*[local-name()='Students' and namespace-uri()='http://tempuri.org/']/*[local-name()='Student'][./*[local-name()='sname'] = 'John' or ./*[local-name()='sname'] = 'Mark'])")


Thanks. SMSVikasK

  • Proposed as answer by SMS Vikas K 16 hours 52 minutes ago
August 25th, 2015 2:00pm

Hi Lathaa,

Similar example discussed click here.

Quick View for xpath condition :

studentCount = 0;

if (xpath(msgStudents, "//*[local-name()='Student'][*[local-name()='sname']='John' or *[local-name()='sname']='Sam']") != null)
{
    studentCount = xpath(msgStudents, "count(//*[local-name()='Student'][*[local-name()='sname']='John' or *[local-name()='sname']='Sam'])"); 
}
// or 

xpath(msgStudents,"count(/*[local-name()='Students' and namespace-uri()='http://tempuri.org/']/*[local-name()='Student'][./*[local-name()='sname'] = 'John' or ./*[local-name()='sname'] = 'Mark'])")


Thanks. SMSVikasK

  • Proposed as answer by SMSVikasK Saturday, August 29, 2015 2:14 PM
Free Windows Admin Tool Kit Click here and download it now
August 25th, 2015 2:00pm

It would be like..but with OR operator i.e the value can be 1234xy OR 1515xy

xpath(incoming schema , "count(//Root node[normalize-space(child element)='1234xy'] and[normalize-space(child element)='1515xy']))

August 25th, 2015 2:18pm

Hi Lathaa,

sharing one example for your scenario, get counts using multiple && conditions.

  • Use LINQ technique to achieve this.
  • Create Utility for this.
<students>
	<Student>
		<ID>1</ID>
		<Name>XYZ</Name>
	</Student>
	<Student>
		<ID>2</ID>
		<Name>STU</Name>
	</Student>
	<Student>
		<ID>3</ID>
		<Name>SMS</Name>
	</Student>
	<Student>
		<ID>3</ID>
		<Name>SMS</Name>
	</Student>
</students>
// Call by creating by object in orchestration

var varCount = GetCountByTwoFields(strDocument);

// Method to get Count

public int GetCountByTwoFields(XDocument doc)
        {
            var varStudents = doc.Descendants().Elements("Student");
            var varCount = varStudents.Where(x => x.Element("Name").Value == "SMS" && x.Element("ID").Value == "3").Count();
            return varCount;
        }

Output for the above is : Count is 2

Thanks, SMSVikasK

Free Windows Admin Tool Kit Click here and download it now
August 25th, 2015 4:16pm

Hi Lathaa,

sharing one example for your scenario, get counts using multiple && conditions.

  • Use LINQ technique to achieve this.
  • Create Utility for this.
<students>
	<Student>
		<ID>1</ID>
		<Name>XYZ</Name>
	</Student>
	<Student>
		<ID>2</ID>
		<Name>STU</Name>
	</Student>
	<Student>
		<ID>3</ID>
		<Name>SMS</Name>
	</Student>
	<Student>
		<ID>3</ID>
		<Name>SMS</Name>
	</Student>
</students>
// Call by creating by object in orchestration

var varCount = GetCountByTwoFields(strDocument);

// Method to get Count

public int GetCountByTwoFields(XDocument doc)
        {
            var varStudents = doc.Descendants().Elements("Student");
            var varCount = varStudents.Where(x => x.Element("Name").Value == "SMS" && x.Element("ID").Value == "3").Count();
            return varCount;
        }

Output for the above is : Count is 2

Thanks, SMSVikasK

  • Proposed as answer by SMS Vikas K 16 hours 52 minutes ago
August 25th, 2015 8:09pm

Hi Lathaa,

sharing one example for your scenario, get counts using multiple && conditions.

  • Use LINQ technique to achieve this.
  • Create Utility for this.
<students>
	<Student>
		<ID>1</ID>
		<Name>XYZ</Name>
	</Student>
	<Student>
		<ID>2</ID>
		<Name>STU</Name>
	</Student>
	<Student>
		<ID>3</ID>
		<Name>SMS</Name>
	</Student>
	<Student>
		<ID>3</ID>
		<Name>SMS</Name>
	</Student>
</students>
// Call by creating by object in orchestration

var varCount = GetCountByTwoFields(strDocument);

// Method to get Count

public int GetCountByTwoFields(XDocument doc)
        {
            var varStudents = doc.Descendants().Elements("Student");
            var varCount = varStudents.Where(x => x.Element("Name").Value == "SMS" && x.Element("ID").Value == "3").Count();
            return varCount;
        }

Output for the above is : Count is 2

Thanks, SMSVikasK

  • Proposed as answer by SMSVikasK Saturday, August 29, 2015 2:14 PM
Free Windows Admin Tool Kit Click here and download it now
August 25th, 2015 8:09pm

Hi Morten,

Yes it should be OR rather than AND. I have made changes to above statement with OR. requirements given weren't appropriate so ahd confusion.

Thanks much for this.

regards,

lathaa

August 26th, 2015 4:59am

Hi Lathaa,

Hope your issue is resolved now :)

Thanks, SMSVikasK

Free Windows Admin Tool Kit Click here and download it now
August 26th, 2015 5:53am

Yes thanks much Vikas  :)

August 26th, 2015 6:37am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics