I'm being stumped by something that should be trivial.
I've got an xml document, which is split using cSplitter using XPath which works fine, but then I want to set headers with values from the split document.
I've got a cSetHeader component with the Language set to XPath and the valid xpath. However, it returns the value as a NodeList object, when I need a string.
If I use an XPath expression that returns a string, it gives an exception as it can't convert to NodeList.
How, in Talend, do I configure the XPath expression to return a string. It seems ok if you're writing the camel directly, as there is a parameter, but I can't see how it is done in Talend.
Thanks!
I've figured it out...
As it's a code generator, talend puts in the .xpath( ... ) whatever you type in the field - so if you want it to generate a string you put
"/your/xpath/here", java.lang.String.class
in the cSetHeader xpath field and the code generator puts your xpath string with the requested class in the right place!
Easy! Now why didn't I think of that earlier...?
Related
Ruby beginner here.
I am trying to understand yield and how to wrap HTML tags around it and I have been having issues with this code.
def tag (tag_name, attributes = nil)
"<#{tag_name}#{attributes}>#{yield}</#{tag_name}>"
end
style_tag = tag("div", ["class=", "red"]) do
tag("h1") do
"Google it"
end
end
my output is :
"<div[\"class=\", \"red\"]><h1>Google it</h1></div>"
Thank you
The issue is not with yield wich seems to be working fine, but with the attributes parameter. Or rather inserting the parameter into the string.
At the moment you are doing an implicit Array.to_s which is where the brackets come from. If you are sure the attributes string is correct, you can do a simple ...#{attributes.join} ... to join all elements to a proper string (provided the HTML syntax is correct and so on).
I am automating a page using selenium with java and trying to use a case insensitive xpath with the help of translate function as follows.
driver.findElement(By.xpath("//a[contains(translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'tools')]")).click();
'tools' text exists on the page as 'Tools'. [T as caps]
Now my question is,
What does '.,' means in the above code?
Using 'tools' in place of '.,' gives all the //a links. Reason?
Whenever I use 'Tools' instead of 'tools' in the above code, it does not work.
Someone help me here.
image 1
image 2
Now my question is,
What does '.,' means in the above code?
Using 'tools' in place of '.,' gives all the //a links. Reason?
Whenever I use 'Tools' instead of 'tools' in the above code, it does not work.
The dot step is an abbreviated syntax, from the specs:
. selects the context node
Because it's used as parameter for a function that expects a string, will be casted by the means of string() function.
The string 'tools' always contains the string 'tools', thus you are not filtering any selected a element when you used instead of .
In the other hand, any lowercase string will never contain the string 'Tools', so you won't be able to select anything.
How to extract the value from a xml tag?
Below is the XML which is stored in a pointer variable response.
<Response>
<ID>App1</ID>
<operationID>654164615</operationID>
<mainReturnResult>
<returnCode>2000</returnCode>
<returnString> Success – Successful Result </returnString>
</mainReturnResult>
<totalDuration>647</totalDuration>
<Result>
<jobID>job1</jobID>
<mainReturnResult>
<returnCode>2000</returnCode>
<returnString> Success – Successful Result </returnString>
</mainReturnResult>
<duration>78</duration>
/*still more xml tags*/
-Data.to.be.taken
data comes here which have to extracted
-Done.with.data
I need only the return code and the data which is at the end of the xml.
I was using strstr to get the value of the tag return code. But when my friend seeing me doing that he said its a bad way to do it.
But, I need only the
1. return code to know the status and
2. to extract the data from the xml.
So, can you please suggest me which is the efficient way of doing these two activities without using any libraries.
Just parse it.
While I've written a lot of code for parsing stuff like this (mostly in C#), you can do something really simple here.
Just scan the text for <returnCode>. The text you want starts after this. It ends at the next occurrence of </returnCode>. Easy.
While generating an XML content, I get an empty node <node/>, and I want it to be <node></node>. (Since <node></node> is the correct form of c14n, the progress called "converting empty elements to start-end tag pairs")
How should I convert it?
There's a way hinted by Jim Garrison(Thank you) to do this,
by using xmlBufferCreate, xmlSaveToBuffer, xmlSaveDoc, xmlSaveClose
with xmlSaveOption: XML_SAVE_NO_EMPTY
Take a look at the libxml2 documentation, specifically xmlSaveOption value XML_SAVE_NO_EMPTY
I found another way which is easier when the nodes are generated under control, by simply giving value "" to the node.
How do you save an array or an ArrayList in VB.NET using My.Settings? I cannot find the array type anywhere, even in the browse window.
I know I can convert the array to a string, but I do not know how to convert a string to an array. I know that if I were to break it at a delimiter then I could convert a string to an array, but my problem is that any text at all could be stored within the array as a single value, so I cannot pick a delimiter that is unlikely to be used.
I was also facing the same problem and I came up with a solution to this.
Here are the steps:
Open up the properties of your app and select settings
select the setting name and then where it says type click on the
arrow and select browse.
in the browse window type in system.collections.arraylist and hit enter!
there you have your array!
You can use array like this:
your_array_name(here_comes_the_item_no.) = whatever
What kind of array? I've had luck using StringCollection for strings. ArrayList works for most anything else (and that's about the only place I'd use arraylist).
I would either use the StringCollection type, and just convert your elements to/from strings when storing them in my.settings, or use XML Serialization to turn the array in to an xml string, and store that in my.settings.