camel:xpath. Selecting multiple values from a single node - xpath

I want to select a multiple values from an XML node.
ex:
<Root>
<SubRoot>
<Parent>Hiddic</Parent>
<Mother>Vim</Mother>
</SubRoot>
<SubRoot>
<Parent>Richie</Parent>
<Mother>Vile</Mother>
</SubRoot>
<SubRoot>
<Parent>Stroog</Parent>
<Mother>Murukku</Mother>
</SubRoot>
</Root>
From this example i want to extract the SubRoot nodes where is equals to Vim and Vile. I am using camel Xpath expression for this. And i am giving the inputs using a properties file.
This is the code i am using:
<setHeader headerName="newBody">
<xpath>//SubRoot[contains(Mother,"${properties:AlgoPosition.product.type.value}")]</xpath>
</setHeader>
The value in the property file is,
AlgoPosition,poduct.type.value = Vim,Vile;
If i give a single value in the property it retrieves me the correct node but when i give multiple values its failing. Please Help me in selecting multiple values.

Related

XPath expression to pluck out attribute value

I have the following XML:
<envelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="vendor">
<fizz buzz="3"/>
</payload>
</envelope>
I am trying to write an XPath expression that will pluck out vendor (value for the payload's class attribute) or whatever its value is.
My best attempts are:
/dataEnvelope/payload[#class="vendor"]#class
But this requires the expression to already know that vendor is the value of the attribute. But if the XML is:
<dataEnvelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="foobar">
<fizz buzz="3"/>
</payload>
</dataEnvelope>
Then I want the expression to pluck out the foobar. Any ideas where I'm going awry?
If you need #class value from payload node, you can use
/dataEnvelope/payload[#class]/#class
or just
/dataEnvelope/payload/#class
At first, your two XML files are out-of-sync - one references envelope and the other references dataEnvelope. So exchange one for the other, if necessary.
So, to get the attribute value of payload, you can use an XPath expression like this which uses a child's attribute value to be more specific:
/envelope/payload[fizz[#buzz='3']]/#class
Output is:
vendor
If the document element can/will change, then you can keep the XPath more generic and select the value of the class attribute from the payload element that is a child of any element:
/*/payload/#class
If you know that it will always be a child of envelope, then this would be more specific(but the above would still work):
/envelope/payload/#class

xpath where && clause

I have xml data like this
<users>
<user email="email#email.com">
<password>pass</password>
..
</user>
</users>
I want to retrieve the user's record (xml format) filtering by email and password.
I have tried
for $user in doc("users")/user
[#email="'.$email.'"]
[password="'.$password.'"]
return $user
but I get errors.
Please, how can I retrieve that user's data in xml format so that I can use something like domdocument or simplexmlparser to get the respective nodes?
My reference was http://www.w3schools.com/xsl/xpath_syntax.asp
You would probably want to combine the constrains to one single constraint
for $user in doc("users")//user[#email="'.$email.'" and password="'.$password.'"] return $user
This could also be achieved in one go by:
doc("users")//user[#email="'.$email.'" and password="'.$password.'"]
HTH,
Peter
The most likely cause of the errors you report is that your query asked for user elements that appear as the outermost element of the users document and which satisfy some further constraints, thus:
doc("users")/user[...][...]
But the XML you show has users, not user, as the outermost element.
In the short run, using ...//user instead of .../user, as is done in prker's answer, will solve this problem. (His recommendation to use only a single predicate makes no sense and has nothing to do with whatever problems you had.) The problem can also be fixed by getting the path right: doc("users")/users/user...
In the long run, you should learn to understand what is happening in your XPath expressions. Here, doc("users") returns the document node at the root of the XML document you specify, and the next step, /user (short for /child::user) asks for an element node named user which is the child of the document node.
It worked with this
'for $user in doc("users")//user
where
$user/password = "'.$password.'" and
$user[#email="'.$email.'"]
return $user ';
Reference from http://www.w3schools.com/xsl/xquery_intro.asp

assign value from attribute_view_gui from select attribute

I have an attribute if type select. When i try to get value from this attribute content it gives the identification number instead of the value. I call like
$node.data_map.my_attribute_identifier.content
This is expected behaviour. https://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Datatypes/Selection
Raw output
The ".content" of an ezcontentobjectattribute object using this datatype returns an array of the identification numbers (as strings) of the selected options.
I want the value not the identification number. I can get that using attribute_view_gui like
attribute_view_gui attribute=$node.data_map.my_attribute_identifier
But i can't assign value to a variable this way. How can i assign value from a select attribute?
First of all i recommend you to always check default templates in your ezpublish to figure out how should template look...
Maybe this example will help:
<input
id="whatever_id_you_like"
type="text" size="50"
name="ContentObjectAttribute_ezstring_data_text_{$node.object.data_map.YOUR_ATTRIBUTE_SHORT_NAME.id}"
value="{$YOUR_VAR}"
/>
or u can use default view for attribute like this:
{attribute_view_gui attribute=$node.data_map.YOUR_ATTRIBUTE_SHORT_NAME}
also might be helpful - way to find correct path (sometimes you need add ".data_int" or ".data_text" on the end of the path to display data):
{$path|attribute(show,depth)} example:
{$node|attribute(show,2)}
or
{$YOUR_FANCY_VAR.content|attribute(show,2)}
You may want to take a look at the view template of ezselection:
ezselection.tpl
This is the code that eZ Publish uses to view the data type.
content of ezselection.tpl:
{let selected_id_array=$attribute.content}
{section var=Options loop=$attribute.class_content.options}
{section-exclude match=$selected_id_array|contains( $Options.item.id )|not}
{$Options.item.name|wash( xhtml )}{delimiter}<br/>{/delimiter}{/section}
{/let}

jMeter CSV_Data_Set config and XML dynamic binding

I am primarily using JMeter -CSV_Data_Config element to bind csv data with a XML template as shown below.
This works beautifully when the data in the excel cells are static ie.. know set of columns. eg. 6 cols in csv file bind to 6 variables in XML file.
Lets say end user decides to have 15 cells of data in the csv file. Can i make the jMeter script dynamic to add new XML elements eg.Item with new attributes based on the number of cells in the csv file ?
I think a beanShell script might help if not ? not sure how .. any help -much appreciated !
Personally I would use the following approach for getting data from CSV file with unknown number of columns:
User Defined Variables (defined variable N with the value of 0)
While Controller
Counter (Start: 1, Increment: 1, Reference Name: N)
Samplers with data-driven logic
and use the following line as condition for the While Controller
${__javaScript("${__CSVRead(/path/to/your/file.csv,${N})}"!="",)}
See __CSVRead() function documentation for more details.

Umbraco: how can i get a node by property value with uQuery?

Maybe someone can help, is it a way to combine an xPath expression to query node by it's property value?
I have a node with custom property "ItemId". I need something like this:
uQuery.GetNodesByXPath("//* [#itemId = '<someId>']")
Thanx in advance!
"//*" Will give you all nodes, so "//*[#itemId = '<someId>']" is asking to give you all nodes with an attribute equal to exactly "<someId>", which you can't have as a valid attribute.
So, if you have <myNode someId='my Id value'></myNode> , then try //*[#itemId='someId']
But remember, this will give you ANY node with that particular attribute ID.
I'm not sure if this is what you're looking for, but please post your XML or a snippet of what you're grabbing, as that will clear up any grey areas.

Resources