How to let special XML chars unconverted in flex? - actionscript-3

That's my xml node:
<node att="something < something else"> </node>
When i write in my code :
trace(xml.node.#att.toString());
it prints out the string :
something < something else
My problem is that i need to print out the orriginal string:
something $lt; something else //put $ instead of &
Does anyone know how to solve this?
Thanks in advance.

Hey !
Just tried this and it seems to work... : )
var xml:XML=<node att="something < something else"> </node>;
trace(xml.toXMLString());//<node att="something < something else"/>
trace(xml.#att.toXMLString());//something < something else

The basic XML Parser will unespace them.
If you want the converted char again, you'll need to reconvert it again using ActionScript 3.
You can also convert it twice, using &lt;

Option 1 - USE <![CDATA[ ]]>
<chapter title="hello" nr="111" src="">
<page>
<text><![CDATA[To adjust <br/><br/>. . . ]]></text>
<text><![CDATA[To adjust <br/><br/>. . . ]]></text>
</page>
</chapter>
Option 2 - use < and > for < and >
Then <br/> = <b/>

Related

How to extract something I want in html using 'xpath'

The html code is looking like this:
<img alt="Papa's Cupcakeria To Go!" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" data-old-hires="" class="a-dynamic-image a-stretch-vertical" id="landingImage" data-a-dynamic-image="{"https://images-na.ssl-images-amazon.com/images/I/814vdYZK17L.png":[512,512],"https://images-na.ssl-images-amazon.com/images/I/814vdYZK17L._SX425_.png":[425,425],"https://images-na.ssl-images-amazon.com/images/I/814vdYZK17L._SX466_.png":[466,466],"https://images-na.ssl-images-amazon.com/images/I/814vdYZK17L._SY450_.png":[450,450],"https://images-na.ssl-images-amazon.com/images/I/814vdYZK17L._SY355_.png":[355,355]}" style="max-width:512px;max-height:512px;">
I want to get "https://images-na.ssl-images-amazon.com/images/I/814vdYZK17L.png" and now I'm using
extract_item(hxs.xpath("//img[#id='landingImage']/#data-a-dynamic-image"))
, what I got is all the content inside that tag.
How can I get the first url only?
If you just want the first URL:
full_content = extract_item(hxs.xpath("//img[#id='landingImage']/#data-a-dynamic-image"))
list_contents = full_content.split(";")
first_image = list_contents[1].replace("&quot","")
print first_image
Also, you can refer this for extracting URL using regex.

.each do else statement in HTML Slim

I have an HTML Slim document and I would like to know how to put an else statement if no results are found. Here is my current code:
- #books.each do |rep|
.row
.large-12.columns
.bookinfo
.name= book.name
= book.title_name
br
= mail_to author.email, author.email
br
a.phonenumber href="tel:#{ author.phone }"= author.phone
Sorry, I am not at all familiar with HTML Slim and I have very little experience with Ruby. Thanks in advance!
What about something like
- if #books.present?
- #books.each do |rep|
.row
... draw the book
- else
.row No Books Here

Parsing html with regex in ruby

Hello every one i have a html code as code bellow. I want to get the text inside <a>(.*)</a>
I want to get this result:
data 1 : hello1
data 2 : hello2
data 3 : hello3
from that input:
<a>
hello1
</a>
<a>
hello2
</a>
<a>
hello3
</a>
To expand on the two comments, the following Nokogiri code will work for your example. You can use either xpath or CSS. A dedicated parser is much more powerful than rolling your own regex.
> require 'nokogiri'
=> true
> doc = Nokogiri::HTML("<a>hello1</a><a>hello2</a><a>hello3</a>")
=> #<Nokogiri::HTML::Document:0x3ffec2494f48 name="document" children=[#<Nokogiri::XML::DTD:0x3ffec2494bd8 name="html">, #<Nokogiri::XML::Element:0x3ffec2494458 name="html" children=[#<Nokogiri::XML::Element:0x3ffec2494250 name="body" children=[#<Nokogiri::XML::Element:0x3ffec2494048 name="a" children=[#<Nokogiri::XML::Text:0x3ffec2493e40 "hello1">]>, #<Nokogiri::XML::Element:0x3ffec249dc88 name="a" children=[#<Nokogiri::XML::Text:0x3ffec249da80 "hello2">]>, #<Nokogiri::XML::Element:0x3ffec249d878 name="a" children=[#<Nokogiri::XML::Text:0x3ffec249d670 "hello3">]>]>]>]>
> doc.css('a').each { |node| p node.text }
"hello1"
"hello2"
"hello3"
=> 0
Update: You'll need the nokogiri gem if you don't have it installed already.
sudo gem install nokogiri
Depending on your setup, you may also need to prepend
require 'rubygems'

Struts 1 bean tag inside HTML quotes

Here is my code:
<html:text name="rptData" property="emailAddress" onblur="checkIfEmpty('<bean:write name="rptData" property="status" />' , this.id)" />
This is nested inside a logic:iterate tag. What i need to do, is to pass value of 'status' to the javascript checkIfEmpty method. But i guess there is some error in the quotes. It is not working properly. Please anyone guide me. Thanks.
You can't nest custom tags like that, period, and it's unfortunate most of the answers imply you can, because that represents a fundamental misunderstanding of JSP.
Ideally, you wouldn't use the <logic:iterate> tag, as its use is not recommended when you have JSTL available: when JSTL and Struts 1 tag functionality overlaps, use the JSTL option. Then use standard JSP EL to access the variable.
<c:forEach items="listOfThings" var="current">
...
<html:text ... onblur="checkIfEmpty('${rptData.status}', ${current.id})" ...
...
In this example I also assumed that this was supposed to refer to the current iteration object, defined in the <c:forEach> tag.
ok after doing some research i found out the answer.
if i have some code like this:
<html:text styleId="emailAddress+<%=statusC.toString() %>" name="rptData" property="emailAddress" />
its output is as follows:
<input type="text" name="emailAddress" value="abc#gmail.com" id="emailAddress+<%=statusC.toString() %>" />
but if i use
<html:text styleId="<%=statusC.toString() %>" name="rptData" property="emailAddress" />
the output is:
<input type="text" name="emailAddress" value="abc#gmail.com" id="Approved" />
That means without string concatenation the output is correct. i.e. only using
styleId="<%=statusC.toString() %>"
rather then
styleId="emailAddress + <%=statusC.toString() %>"
or even
styleId="emailAddress" + <%=statusC.toString() %> - This results in an error, though
yeilds correct output.
So the workaround is to first intialize a complete java String in a scriplet then use it inside the styleId tag.
<% String emailId = "emailAddress" + statusC.toString() ;%>
<html:text styleId="<%=emailId%>" name="rptData" property="newEmailAddress" />
It will work fine. Cheers !
You might want to try adding some escape characters while using double quotes inside double quotes like in your case it would be some like:
onblur="checkIfEmpty('<bean:write name=\"rptData\" property=\"status\" />' , this.id)"
Try this:
<html:text name="rptData" property="emailAddress" onblur="checkIfEmpty('<bean:write name=\'rptData\' property=\'status\' />' , this.id)" />

Select distinct-values according to child node in XQuery

Let's say I have the following XML:
<info>
<channel>
<A>
<X>
<title>title1</title>
</X>
<Y value="20"/>
</A>
</channel>
<channel>
<A>
<X>
<title>title1</title>
</X>
<Y value="20"/>
</A>
<A>
<X>
<title>title2</title>
</X>
<Y value="20"/>
</A>
</channel>
</info>
and the following XQuery
{
for $A in doc('test.xml')//A
let $TITLE := $A/X/title
where string($A/Y/value) > 20
return
string($TITLE)
}
this, of course, outputs:
title1
title1
title2
How can I use distinct-values in order to remove duplicates? I wonder because for essentially only gives me one item per iteration and I can't call distinct-values on $A. Or is there any other way to remove duplicate output?
The problem is that I need to refer to another node, so basically calling distinct-values(doc...) doesn't work, as it doesn't return nodes.
UPDATE
to filter duplicate nodes, use a variation of the xpath from this answer:
//A[index-of(//A/X/title, X/title)[1]]
this gives you all the As with different titles.
you can expand this xpath expression to also filter on Y - no need for XQuery FLWOR.
UPDATE END
apply the distinct-values to the xpath expression over which you want to iterate:
for $title in distinct-values(doc('test.xml')//A/X/#title)
return string($title)
or just
distinct-values(doc('test.xml')//A/X/#title)