Im working with the HtmlAgilityPack lib and having a few questions of understanding from my limited xpath knowledge. As the code sample below show, from immediate window, table is a htmlnode selected from DocumentNode. So with "/div" none is selected, "div" the one div child is selected, "//div" have selected all the divs in the document(so it did not find only its descendants. Therefor i have picked table.Descendants instead which give me the 5 divs i want.
I would like to know, is using xpath with the selectNodes method faster then just using linq (table.Descendants.Select(n=>n.attribute["class"] == "someclass")) ect.
And what is it i dont understand about xpath, why cant i select a specific elements descendants?
table.SelectNodes("/div");
null
table.SelectNodes("div")
{HtmlAgilityPack.HtmlNodeCollection}
_items: Count = 1
_parentnode: null
Count: 1
IsReadOnly: false
table.SelectNodes("//div")
{HtmlAgilityPack.HtmlNodeCollection}
_items: Count = 84
_parentnode: null
Count: 84
IsReadOnly: false
table.Descendants("div").ToArray()
{HtmlAgilityPack.HtmlNode[5]}
[0]: Name: "div"}
[1]: Name: "div"}
[2]: Name: "div"}
[3]: Name: "div"}
[4]: Name: "div"}
Related
I want to import all products filtering these they applied all 3 criteria:
1) they are in stock (DIM)
2) stock is more than 3 pcs (stock_indicator)
3) and they belong to one (any) of these groups 1 or 4
I want all 3 criteria, but in 3rd any of these options
i.e.:
/product[dim1[1] = "1" and stock_indicator[1] > 3 and group[1] = "1" or group/category/id[1] = "4"]
The above does not returns any product, like no product have all these requirements.
What am I doing wrong?
Dim = availability
XML sample:
/product[dim1[1] = "1" and stock_indicator[1] > 3 and group[1] = "1" or group/category/id[1] = "4"]
First of all your XPath assumes that all product elements are at root level, which would not make for a well-formed XML document; the all should be wrapped in some element.
If that is no problem in your environment (since we do not know the whole setup from your question) probably the most prominent problem in your XPath is that you try to compare the value of stock_indicator against a xs:integer but in fact your data sample encodes them as xs:string.
Consequently
stock_indicator[1] > 3
will always return falseā¦
Try
stock_indicator[1]/number() > 3
or
number(stock_indicator[1]) > 3
instead.
Nevertheless depending on the data structure (e.g. multiple stock_indicatorelements in one product [whatever that might mean]) this could return false positives.
You can use the following XPath to filter the products :
//product[availability="1"][stock_indicator>3][group/id=1 or group/id=4]
// at the beginning as stated by #Benjamin W. Bohl to catch all products
availability is used instead of "Dim"
cleaner syntax used for predicates
no position indexes used ([1]) assuming you only have 1 availability, 1 stock_indicator, 1 id per group in each product
XML used to test.
XPath :
XML is filtered (2 of the 4 products fulfill the conditions) :
I'm used to writing in JavaScript so I am approaching this thinking about SWITCH statements and of course the classic if else...
I just want to check if the data in a row is TRUE, and if it is count it. If the value is not true, don't add it to the count.
I'm thinking something like this would work:
CASE
WHEN is_it_true_or_false = false
THEN COUNT_DISTINCT ( id ) //using id to address that specific row and add it to the count
END
It can be achieved by using either of the following CASE statements and aggregating the Calculated Field as required - COUNT_DISTINCT (Unique IDs of TRUE values) or COUNT (All TRUE values):
1) Where is_it_true_or_false is a Boolean OR String Field:
CASE
WHEN REGEXP_MATCH(is_it_true_or_false, "((?i)TRUE)") THEN id
ELSE NULL
END
2) Where is_it_true_or_false is a Boolean Field:
CASE
WHEN is_it_true_or_false = TRUE THEN id
ELSE NULL
END
Google Data Studio Report and GIF to elaborate:
I am displaying a list on my page in the format of cards but the image is not showing up - only a grey circle. Here is my query for the dynamic list:
SELECT null as level_value,
TITLE as label,
null astarget,
null as is_current,
IMG_PATH as image,
'width="40" height="40"' image_attribute,
TITLE as image_alt_attribute,
DECRIPTION as attribute1
FROM TABLE1
ORDER BY TITLE
I also tried:
SELECT null as level_value,
TITLE as label,
null astarget,
null as is_current,
'<img src="' || IMG_PATH || '"/>' as image,
'width="40" height="40"' image_attribute,
TITLE as image_alt_attribute,
DECRIPTION as attribute1
FROM TABLE1
ORDER BY TITLE
I have noticed when inspecting the page that APEX adds my image tag to the class of a span:
<span class="t-Icon <img src='my image path' />">
instead of just adding an image to the card
I found a solution. Actually two solutions.
1) Modify dynamic list to utilize CARD_INITIALS and attributes
SELECT null as level_value,
TITLE as label,
null astarget,
null as is_current,
IMG_PATH as CARD_INITIALS,
'width="40" height="40"' image_attribute,
TITLE as image_alt_attribute,
DECRIPTION as attribute1,
'' as attribute2,
'<img src="' || IMG_PATH || '"/>' as attribute3
FROM TABLE1
ORDER BY TITLE
Setting both CARD_INITIALS and attributes3 that way was necessary - other combinations did not work properly.
Then, in List region attributes, set List template to Cards, style to featured, and Icons to - Display Initials.
2) Classic report - setting its attributes to Cards template and using CARD_INITIALS, CARD_TITLE, and CARD_TEXT as aliases in the source query. Both methods produce desired results
The appearance and structure of these lists are pre-defined. I think this list template understands an image as a css class.
To work, you need to provide a valid css class
list of icons/class: https://apex.oracle.com/pls/apex/f?p=42:icons
EDIT.
Maybe you can copy this list template that you are trying to use and make the modification needed to get the url of an image.
To do this, you need to go to shared components >> Templates >> Find your template list >> click on the last column of the report to copy >> Edit the html to receive the url of an image. On this page you will find several substituition strings.
The one that receives the "image" is something like #ICON_CSS_CLASSES#, but it is by default used in a "span" class, its change would be to create an "img" and put that substituition string in the "src" of that "img", something like
<img src="#ICON_CSS_CLASSES#">
I have a small application that displays a list of shortURLs to a user. I'm using ASP.NET MVC3, Entity Framework, and an Oracle backend. I'm also using the PagedList library by Troy Goode (https://github.com/TroyGoode/PagedList)
I want the user to see the very last entry first, similar to how blog comments are ordered. To do this I added an "orderby descending" clause to the LINQ statement:
var links = from l in db.LINKS
orderby l.ID descending
select l;
In debug the "links" object is ordered as expected (in descending order, by the primary key "ID").
Now I want to pass this list of links to the view using the .toPagedList() method:
int pageSize = 3;
int pageNumber = (page ?? 1); // "page" comes from the request, if null set to 1
return View(links.ToPagedList(pageNumber, pageSize));
This works great if I only have 3 records (refer to "pageSize" above). However, when I add a 4th record I get unexpected behavior. Because I have the pageSize set to 3, adding a fourth record means there will be 2 pages. I would expect the ordering to be as follows:
Page 1:
ID: 4
ID: 3
ID: 2
Page 2:
ID: 1
That is not the case, what actually happens is this:
Page 1:
ID: 3
ID: 2
ID: 1
Page 2:
ID: 4
So my question, what the heck am I doing wrong here? Why is PagedList not following the order defined by the "orderby l.ID descending" expression in the LINQ statement? It is baffling to me because in the debugger it is clear that the "links" object is ordered properly before the .toPagedLIst() is used on it.
Any help is greatly appreciated!
You could try:
return View(links.ToPagedList(pageNumber, pageSize, m => m.ID, true));
It's off the top of my head, so I'm sorry if it doesn't work perfectly...
-- Wow, just noticed the date on this one... I need to stop trawling the unanswered pages without sorting by date!
I'm trying to use an AdvancedDataGrid to display some grouped data. Normally flex displays this in a "tree view" with a folder icon represent the group. I need to group the data based on an integer ID field in my object, but I'd like the label for the folder icon to display the groupName field in my object.
Here's a little example:
{groupName: group1, ID: 1234}
{groupName: group2, ID: 5678}
<mx:grouping>
<mx:Grouping label="Group"> <--- The label of the whole column
<mx:GroupingField name="ID">
</mx:Grouping>
</mx:grouping>
Resulting output:
=== Group ===
+ 1234
- child
- child
+ 5678
...
But I'd really like to output:
=== Group ===
+ group1
- child
- child
+ group2
...
If anyone has any tips I'd appreciate it.
-- Dan
Have a look at GroupingField#groupingFunction. From the adobe docs:
A function that determines the label for this group. By default, the group displays the text for the field in the data that matches the filed specified by the name property. However, sometimes you want to group the items based on more than one field in the data, or group based on something that is not a simple String field. In such a case, you specify a callback function by using the groupingFunction property.
private function myGroupingFunction(value:Object, field:GroupingField):String