xml parsing getting inner value - powershell

I am trying to understand how nodes work in order to get their values.
The sample XMl code is
<MediaContainer size="1">
<Video addedAt="1463113546">
<User id="365343" thumb="something" title="UserA"/>
</Video>
</MediaContainer>
I know below will get the User ID using powershell, however trying to also get the title value which contains the username.
$xml.MediaContainer.Video.User.id
When looping through not every line that has a User id will have a thumb value. In other words it can also say
<User id="343" title="UserB"/>

First ,
[System.Xml.XmlDocument]$xml = new-object System.Xml.XmlDocument
$xml.load(<file_path>)
Then,
Get User ID : $xml.MediaContainer.Video.User.id
Get title : $xml.MediaContainer.Video.User.title

Related

Getting HTML id tags using perl

I can get html parameters like
name="something"
like this
cgi->param("something")
then what about when i want to get for id
id="something"
The browser only sends the name and and value of successful controls, and the name is set by the element's name attribute. Their id attribute is not sent, so you will need to use the correct attribute.

grails access form attributes in controller

In grails i have a form with g:field tags like:
<g:field name="test" from="0..20"/>
I am trying to find a way how I can access the "from" attribute in my controller.
I can get the "value" attribute by using:
print params.test
I have tried:
print params.test.from
I'm sure there must be a way to do this but I can not seem to find it.
What I am wanting to achieve by this is perform validation so that the value does not go outside the the from range.
I know that this can be added in the domain, but in my situation I need to allow the user to overwrite the range constraints.
Any ideas?
By the time that code hits the browser, it is just HTML. from doesn't exist anymore. If that is being rendered into some sort of client side validation, that's not going to get submitted back to the server in a form submit.
If you explain what you are really needing to do in your question, I can provide a better answer.
You can pass the "from" values as hidden fields.
<g:hiddenField name="min" value="0" />
<g:hiddenField name="max" value="20" />
Something like that.

How do I use Perl's Remote::Selenium::WebElement to verify the URL a hyperlink will take me to?

Seems like it should be straightforward but I can't seem to get to the bottom of it.
Here's the HTML I'm working with:
<li id="a" class="FILElevel3" onclick="changeMenu("b")">
<a onclick="stopBubble(event);" href="javascript:LinkPopup('/sub/URL.html')">Visible Text</a>
I'm able to find the element using XPaths:
my $returned_asset = $sel->find_element("//*[\#class='LINKlevel3']");
And I can verify this works because I'm able to extract the visible text from it:
my $returned_name = Selenium::Remote::WebElement::get_text($returned_asset);
I just can't seem to find the sequence to pull the HREF attribute from the element to put the link's URL into a verifiable string. Should I be able to do this using WebElement's get_attribute() method? I've tried variations on this:
my $returned_URL = $returned_asset-> Selenium::Remote::WebElement::get_attribute("a/href");
...where I've plugged in everything I could think of for that "a/href" string. What should go in there?
In the end I'd like to be able to put "javascript:LinkPopup('/sub/URL.html')" into a string and verify that my URL is in there.
have you tried
my $returned_asset = $sel->find_element("//*[\#class='LINKlevel3']/a");
my $returned_URL = $returned_asset->Selenium::Remote::WebElement::get_attribute("href");

struts 2 s:date tag with value from variable in request with it's name in request

I have a problem in my web app with struts 2 and a date value. I've got a form and inside it an s:textfield that shows a date value. I read this value from request, and the problem is that the name of that value is in other variable.
The Action I'm calling does this:
...
public String execute(){ return SUCCESS;}
public MyObject getObject1(){
MyObject result = new MyObject();
result.setDate(new java.util.Date());
return result;
}
...
On SUCCESS it goes to my form.
The code in my form (what I was wondering to write) is:
<s:form action="save">
<s:set name="objName" value="object1"></s:set>
<jsp:include page="../includedform.jsp"></jsp:include>
</s:form>
And in the "includedform.jsp" there is:
<s:textfield name="%{objName}.date" label="Date" >
<s:param name="value">
<s:date name="%{%{objName}.date}" format="dd/MM/yyyy" />
</s:param>
</s:textfield>
The syntax:
%{%{objName}.anagrafica.dataNascita}
doesn't work (it shows nothing, obviously). So i'll need something like this but working :)
Other tags s:textfield inside "includedform.jsp" (ommited in the code bellow for simplicity) without date fields are working, because I am using only the name attribute and struts looks automatically for the value. This is the code I use for these textfields:
<s:textfield name="%{objName}.name" label="Name"/>
your question is very confusing and you need to rephrase to make it more clear and readable.
i am not sure why you are doing this
<s:textfield name="%{objName}.date" label="Date" >
while this can be done like
<s:textfield name="objName.date" label="Date" > OR
<s:textfield name="%{objName.date}" label="Date" >
when you write objName.date OGNL assume that you have a bean in your action class namely objName and this bean has property namely date, s ultimately this will get converted to
getObjName().getDate() by ONGL
On a similar fashion <s:date name="%{%{objName}.date}" format="dd/MM/yyyy" /> datee tag works
For more details please refer to the official doc
Struts2 Date tag
There is one solution which i tried and it worked :)
1)Keep the column in which you want to store date in database's table in "DATE" data type only.
2)Use only Textfield tag in JSP page.Dont use Date tag.
Note:Make sure that you make user input date in YYYY-MM-DD format only by placing a placeholder in textfield tag !
3)Keep the variable for accessing that field of string type only.Dont use DATE data type.
4)Now run Query: Select DATE_FORMAT(datecolumnname,'%d/%m%/Y') as date_two from tablename; and you will get date from that columnin dd/mm/yyyy format even if it is stored in YYYY-MM-DD format in table .
5)And you can also compare your datecolumn's data with curdate() and related functions as well and it works :) .
6)Like i used query: Select id,name,DATE_FORMAT(datecolumnname,'%d/%m/%Y') as datecolumn2 from tablename where datecolumnname >= curdate();

How to display different value in struts 2 select

I want to know how to display a different value in struts 2 select.
eg: i want to put Jan,Feb as month where the value should pass 1,2 respectively.
if anybody aware of this please let me know
thank you.
See the following example (from the Struts 2.1.8 API doc) :
<s:select label="Months"
name="months"
headerKey="-1" headerValue="Select Month"
list="#{'01':'Jan', '02':'Feb', [...]}"
value="selectedMonth"
required="true"
/>
The list attribute contains a map where the key is the value that will be sent and the value is the value that will be displayed.
Of course, months are static, but you could use a list of domain objects or whatever beans you need. In this case the list should be stored, typically as a field of your action class. Then you will refer to the list or map :
<s:select label="User"
name="users"
headerKey="-1" headerValue="Select User"
list="users"
value="selectedUser"
required="true"
/>
In this case your action will contain a map with the usernames and their ids and a getter for it : getUsers().
If the getUsers() method of your action returns a list of User objects, and the User class has at least (let's assume) the id and username fields, you will have to specify which field to use for value to be passed and which field to use for display in the select. This is done with the listKey and listValue attributes of the select tag :
<s:select label="User"
name="users"
headerKey="-1" headerValue="Select User"
list="users"
listKey="id"
listValue="username"
value="selectedUser"
required="true"
/>