JSoup - how does HTML structure affect response? - css

Trying to learn JSoup but having problems with response that may be due to structure issues (or stupidity, you tell me!). I do a simple query for "a[href]" but it only finds a subset 13 (text search tells me there are 162!). Why does it not find all?
Document doc = Jsoup.connect(J_URL).get();
String srchCSS = "a[href]";
Elements select = doc.select(srchCSS);
Iterator<Element> iterator = select.iterator();
Log.w(TAG, "'" + srchCSS + "' # " + select.size());
while (iterator.hasNext()) {
Element x = iterator.next();
System.out.println("'" + srchCSS + "': " + x.text());
}
Log.e(TAG, "%%% COMPLETE %%%");
I want to get the text from 'p' (see RED arrow). The a[href] above it is NOT being found?!?

Related

fetching multiple images from url of xml response in xamarin forms

Can anyone guide me how to load images through image_url tags in my image control named BOOK_URL under a loop? i have fetched other book info under similar_books tag of each book tag but unable to fetch images of all book tags in my image control.
My code looks like this.
var xdoc = XDocument.Load("https://www.goodreads.com/book/title.xml?key=Uxb0zPb86N4STVy2ECWYA&title=" + title.Text);
IEnumerable<XElement> allElements =
xdoc.Descendants("similar_books").Descendants("book");
foreach (XElement result in allElements)
{
BOOK_URL.Source = BOOK_URL.Source + "\n"+
ImageSource.FromUri(new Uri(result.Element("image_url").Value)) ;
search.Text = search.Text + "\n" +
" Book Name: " + result.Element("title").Value + "\n" +
" ISBN: " + result.Element("isbn").Value + "\n" +
"Average Ratings: " + result.Element("average_rating").Value + "\n";
}
}
Also my url of xml response look like this:
https://www.goodreads.com/book/title.xml?key=Uxb0zPb86N4STVy2ECWYA&title=DUNE
i am getting all info except for images. Please help me to fetch all images of all book tags as i have fetched other book info rather than images.
this is garbage and should not even compile
BOOK_URL.Source = BOOK_URL.Source + "\n"+
ImageSource.FromUri(new Uri(result.Element("image_url").Value));
assuming that BOOK_URL is an Image control, you want to do
BOOK_URL.Source = ImageSource.FromUri(new Uri(result.Element("image_url").Value));
note that if you have multiple image urls, only the last one in the loop will be assigned
if you have two image controls, you could do this
IEnumerable<XElement> images = xdoc.Descendants("similar_books").
Descendants("book").
Descendants("image_url");
image1.Source = ImageSource.FromUri(new Uri(images[0].Value));
image2.Source = ImageSource.FromUri(new Uri(images[1].Value));

Trying to assign a value to CSS in typescript doesn't work

I have script that is taking a HTMLElement and the css.top and css.marginLeft of an element which refuses to set the properties in TypeScript.
here's my code:
let moveable1: HTMLElement = document.getElementsByClassName('moveable1')[0] as HTMLElement;
Here's how I'm getting the values and "trying" to set the properties.
console.log("**style.top** = " + (moveable1.style.top =
String((+this.chatScrollTop + +this.boxScrollTop).toFixed(0))));
console.log("**style.marginLeft** = " + (moveable1.style.marginLeft = String((+this.chatScrollLeft + +this.boxScrollLeft).toFixed(0))));
moveable1.style.top = String(moveable1.style.top);
moveable1.style.marginLeft = String(moveable1.style.marginLeft);
What's happening is:
moveable1.style.marginLeft and moveable1.style.top ALWAYS equals ""
I don't understand.
The console logs are reporting the correct values
style.top = 69
style.marginLeft = 100
top: **<<<=== "EMPTY"** and should be 69
marginLeft: **<<<=== "EMPTY"** and should be 100
Thoughts, anyone?
UPDATE:
Zeh suggested the solution:
I modified it a wee bit...
let top = +this.chatScrollTop + +this.boxScrollTop;
const marginLeft = this.chatScrollLeft + this.boxScrollLeft;
moveable1.style.top = top.toFixed(0) + "px";
moveable1.style.marginLeft = String(parseInt(marginLeft).toFixed(0)) + "px";
console.log("top: " + moveable1.style.top);
console.log("marginLeft: " + moveable1.style.marginLeft);
THANK YOU ZEH!
You're setting a style property to a number and then trying to re-read and convert it to a string. This doesn't work; top (et al) cannot be numbers therefore they're kept at their previous value("").
Also, you need units ("px", "pt", etc) when setting a style, otherwise it won't set either, even if it's a string. Hence when you try converting them from number to string you get another blank string.
// This returns 1
console.log(document.body.style.top = 1);
// Nevertheless, it didn't work, since this returns ""
console.log(document.body.style.top);
This is not a TypeScript problem, this is a JavaScript (rather, a DOM) "problem".
My suggestion is to simplify this code. It's not just hard to read, it's doing a lot that it shouldn't be doing - unnecessary conversions, depending on assignment side effects, etc.
Something like this should work:
const top = this.chatScrollTop + this.boxScrollTop;
const marginLeft = this.chatScrollLeft + this.boxScrollLeft;
moveable1.style.top = top.toFixed(0) + "px";
moveable1.style.marginLeft = marginLeft.toFixed(0) + "px";

how to compare asp.net radio button list values

I am trying to fix a search tool for work. This is the first time I have encountered ASP.NET. The current search tool has a radio Button list with three options of how to search our local directory. However the person that worked on this project before me did not finish the code and has since quit. The radio buttons as they are not do not affect the search query as I have noticed that no matter what option you pick the query is the same.
This is my attempt to rewrite the search function to incorporate the three radio button options. However when I incorporate this function into the rest of the code the page does not render at all and I am not getting the error. I dont think I made an error in the query strings because I took the original one and made variations of it by omitting Contains statements. I'm assuming the error comes from my if statements or how I am trying to compare the asp.net RadioButtonList ListItem values.
protected void btnclick_WorkspaceSearch(object sender, EventArgs e){
string strSearchTerm=tbSearch.Text.Trim()
if (rblSearchOption.SelectedValue == "all"){
// Find the search term in either a file name or file content
string indexQuery = "SELECT docauthor,doctitle, FileName, Path, Write, Size, Rank";
indexQuery += "FROM " + "Workspace" + "..SCOPE() WHERE ";
indexQuery += "CONTAINS(FileName, '\"" + strSearchTerm + "\"') ";
indexQuery += "OR CONTAINS(Contents, '\"" + strSearchTerm + "\"') ";
indexQuery += "ORDER BY Rank DESC";
}
if (rblSearchOption.SelectedValue=="names"){
// Find the search term in a file name
string indexQuery = "SELECT docauthor,doctitle, FileName, Path, Write, Size, Rank";
indexQuery += "FROM " + "Workspace" + "..SCOPE() WHERE ";
indexQuery += "CONTAINS(FileName, '\"" + strSearchTerm + "\"') ";
indexQuery += "ORDER BY Rank DESC";
}
if (rblSearchOption.SelectedValue =="contents") {
// Find the search term in a file's content
string indexQuery = "SELECT docauthor,doctitle, FileName, Path, Write, Size, Rank";
indexQuery += "FROM " + "Workspace" + "..SCOPE() WHERE ";
indexQuery += "CONTAINS(FileName, '\"" + strSearchTerm + "\"') ";
indexQuery += "ORDER BY Rank DESC";
}
searchIndex(indexQuery);
lit_strQueryString.Text = indexQuery;
}
I figured out the problem. For those that commented thank you for your input I did make some necessary changes to help correct potential errors. As for the original question to compare listItem values the line that I used was :
if (rblSearchOption.SelectedItem.Value =="contents"){
//logic here
}
i had tried this before but it did not work. I'm assuming because of the errors pointed out in the comments.
Additional Notes(based on the comments):
The code above has a missing ; in line1
string index query should be declared and initiated outside of the if statements.
Once again thank you to those who attempted to help me.
Glad you found your problem, a bit unrelated but looking at your code I would say it needs some serious refactoring. This code can be simplified by:
1) Using a switch statement.This will help evaluating the selected value of the radio button list just once unlike your code
2) Using a StringBuilder to construct the query
3) Removing repetition - the append logic for names and contents is exactly the same you can remove the repetition by using two case expression and providing one statement to execute.
System.Text.StringBuilder indexQuery = new System.Text.StringBuilder();
indexQuery.Append("SELECT docauthor,doctitle, FileName, Path, Write, Size, Rank FROM Workspace..SCOPE() WHERE ");
switch(rblSearchOption.SelectedItem.Value)
{
case "all":
indexQuery.AppendFormat("CONTAINS(FileName,'{0}') ",strSearchTerm);
indexQuery.AppendFormat("OR CONTAINS(Contents,'{0}')",strSearchTerm);
indexQuery.AppendLine("ORDER BY Rank DESC");
break;
case "names":
case "contents":
indexQuery.AppendFormat("CONTAINS(FileName,'{0}')",strSearchTerm);
indexQuery.Append("ORDER BY Rank DESC");
break;
}
searchIndex(indexQuery.ToString());
lit_strQueryString.Text = indexQuery;

ASP.net Entity Framework Rows Returning Duplicated

I am getting data from these two tables using linq to entities, relationships exist between tables on primary foriegn key basis, result set is coming but every row is repeating multiple times in reult however in Db there are not duplicate rows. Don't understand how to resolve this.
here is piece of code:
StringBuilder sb = new StringBuilder();
string text = txtBoxSearch.Text;
OLSContainer ols = new OLSContainer();
var result = from tex in ols.COURSEs
from another in ols.UNITs
where tex.courseName.Contains(text) || tex.description.Contains(text) || another.unitName.Contains(text)
select new { tex,another };
foreach (var cours in result)
{
sb.AppendLine("<h2 id='" + cours.tex.courseID + "'><a href='admin.aspx?id='" + cours.tex.courseID + "''>" + cours.tex.courseName + "</a></h2>");
}
foreach (var cours in result)
{
sb.AppendLine("<h2 id='" + cours.another.unitID + "'><a href='admin.aspx?id='" + cours.another.unitID + "''>" + cours.another.unitName + "</a></h2>");
}
The problem is this:
var result = from tex in ols.COURSEs
from another in ols.UNITs
It is a cross join. It matches every course with every unit. It doesn't use any FK/PK because no relation (navigation property) is used in this query. To use the relation you have to modify it to:
var result = from tex in ols.COURSEs
from another in tex.SomeNavigationProperty // tex

Inner query in fusion tables

This query will take input from three drop down box and a text box and it work's fine as expected.But my requirement is i need to use another three drop down box and a text in order to query much deeper.So,i need to hold the result of first query and also second query.How should i do.Help me.
That another three drop down box value is also obtained from the same variable's as 'operator','textvalue','querypass'.
function querymap()
{
var operator=document.getElementById('operatorstring').value.replace(/'/g, "\\'");
var textvalue=document.getElementById("text-value").value.replace(/'/g, "\\'");
var querypass=document.getElementById('query-pass').value.replace(/'/g, "\\'");
var searchStringe = document.getElementById('Search-stringe').value.replace(/'/g, "\\'");
var searchString = document.getElementById('search-string').value.replace(/'/g, "\\'");
{
layer.setQuery("SELECT 'geometry'," + querypass + " FROM " + tableid + " WHERE " + querypass + " " + operator + " '" + textvalue + "' AND VillageName = '"+ searchStringe+"'");
}
}
You can have as many AND conditions in your query as you want. No reason not to also check e.g. textvalue2, querypass2, searchString2, etc. and add them to your query. See this setQuery() answer which may give you some ideas. You'll need to set all your search conditions each time you call layer.setQuery() or layer.setOptions({query: ...});

Resources