Regular Expressions (HTML parsing on iPhone) - iphone

I am trying to pull data from a website using objective-c. This is all very new to me, so I've done some research. What I know now is that I need to use xpath, and I have another wrapper for that called hpple for the iPhone. I've got it up and running in my project.
I am confused about the way I retrieve information from the site. Apparently I am to use regular expressions in this line of code:
NSArray * a = [doc search:#"//a[#class='sponsor']"];
This is just an example. Is that stuff in the search:#"...." the regular expression? If so, I guess I can develop the hundreds of patterns that I will need for my program to parse the site (I need a lot of data), but is there a better way? I'm very lost in this. Any help is appreciated.

The parameter is an XPath, not a regular expression. Here's a breakdown:
All xpaths are interpreted relative to a context node. In this case, it's the root node.
// is an abbreviation meaning "all descendents"
a means "all child nodes with a node type of 'a'" (in HTML, that's anchors)
[...] contains a predicate, refining just which a to match
# is an abbreviation for attribute nodes
#class means an attribute named "class"
#class='sponsor' means a class attribute equal to "sponsor". Note this will not match nodes with a class containing "sponsor", such as <a class="big sponsor" ...>; the class must be equal.
All together, we have "'a' nodes descending from the root that have class equal to 'sponsor'".

That is an XPath expression, not a regular expression. The W3C has an XPath reference here: http://www.w3.org/TR/xpath/. Basically you are searching for <a> elements with the class "sponsor".
Note that this is a good thing! Regular expressions are bad for parsing HTML.

Related

mapbox gl setFilter filter by indexOf, contains, or substring

I want to use setFilter expression to filter by substring for a given feature property inside a tileset. Note: I do NOT want to have to load an array of features external to the tileset, I want it to use setFilter only, not getFeatures functions and no looping. If user begins typing, "smith .." it would filter out features as they typed using setFilter only.
I only see "==" or "match" but neither do case insensitive substring filtering, such as indexOf, contains, Like, etc. Something like ['contains', feature.prop, 'smi'] then ['contains', feature.prop, 'smith'], for example.
I see the example on mapbox examples, for filtering as you type, but I want to only use setFilter. It doesn't look like it supports what I want to do, but I thought I'd ask anyway. It is a waste of client-side resources to have to populate any local array of features from the tileset. It defeats the purpose of putting the data inside a tileset to begin with.
Any standard expression for parsing a feature property by a partial string, not an exact match?
As you have noticed, Mapbox-GL expressions don't support substrings or regexes. So I think the only workaround is along the lines you mentioned: getting a list of attribute values and using that as an autocomplete.
There are two ways to get that list of attribute values that don't require making separate, arguably redundant, queries.
Use the values within the TileJSON. Depending how the TileJSON is generated, it often contains a list of the most common values for each attribute (up to 1000 or so, I think).
Use querySourceFeatures() to fetch all features within the current viewport, then filter down to find the values of the attribute you care about. This won't help if the user wants to filter towards something which is currently outside the viewport.
Now mapbox support to filter for tyle layer for sub string from string
expression code is
['in', {filter-substring-value}, ['string', ['get', {mapbox-property-field-string}]]]

Reading CSV file with Spring batch and map to Domain objects based on the the first field and then insert them in DB accordingly [duplicate]

How can we implement pattern matching in Spring Batch, I am using org.springframework.batch.item.file.mapping.PatternMatchingCompositeLineMapper
I got to know that I can only use ? or * here to create my pattern.
My requirement is like below:
I have a fixed length record file and in each record I have two fields at 35th and 36th position which gives record type
for example below "05" is record type which is at 35th and 36th position and total length of record is 400.
0000001131444444444444445589868444050MarketsABNAKKAAAAKKKA05568551456...........
I tried to write regular expression but it does not work, i got to know only two special character can be used which are * and ? .
In that case I can only write like this
??????????????????????????????????05?????????????..................
but it does not seem to be good solution.
Please suggest how can I write this solution, Thanks a lot for help in advance
The PatternMatchingCompositeLineMapper uses an instance of org.springframework.batch.support.PatternMatcher to do the matching. It's important to note that PatternMatcher does not use true regular expressions. It uses something closer to ant patterns (the code is actually lifted from AntPathMatcher in Spring Core).
That being said, you have three options:
Use a pattern like you are referring to (since there is no short hand way to specify the number of ? that should be checked like there is in regular expressions).
Create your own composite LineMapper implementation that uses regular expressions to do the mapping.
For the record, if you choose option 2, contributing it back would be appreciated!

Kentico Nested Macro Comparison

I want to compare a url to a specific path to see if they match. I have tried so many variations and just can't get it to work, the two items I need to use are
{%CurrentDocument.RelativeURL.Replace("~","")%}
and
{&/{0}/{1}/{2}|(tolower)&}
In the current test scenario, both of these return the same string, however, when I put them together
{%CurrentDocument.RelativeURL.Replace("~","")|(equals){&/{0}/{1}/{2}|(tolower)&}|(truevalue)yes#%}
I get a false result displaying, I'm pretty positive it's because I can't nest a path expression inside an expression but not sure if there is another way? Any help would be appreciated.
Thanks
According to the documentation you should be able to substitute path macro with {%Path.path%}. Then there is no need to nest different types of macros but use the Path the same way as CurrentDocument.

Does the w3c.org site have documentation on "select"?

I cannot work out where this doco might be - i'm assuming they do have something on it. I realise this is a dead simple question, but no amount of searching is bringing this up for me.
Bing/DuckDuck etc search cannot find anything particularly relevant, and the only w3c.org links I followed went to "functions", which apparently "select" isn't.
EDIT (Apologies for ambiguity) I am looking for the definition of something along the lines of :
<xsl:variable name="variableName" select="some/path/here" />
That is an XSLT variable. Like many other XSLT elements, it has a select attribute that takes an XPath expression as a value. The value of this attribute just typically happens to be an XPath expression, but the attribute itself isn't directly related to XPath, so you won't find it documented in the XPath spec.
You code fragment is in XSLT, so the specification you want is either "XSLT 1.0" or "XSLT 2.0", which you can find very easily by using these as Google search terms. The value of the select attribute is an XPath expression, so you may also want the XPath 1.0 or XPath 2.0 specification; these can be found the same way.

Selecting Multiple Classes in Jquery

I see some posts on this same issue but would like further clarification as I cannot get any of these answer to work especially as I can't pick the answer out of the Jquery documentation.
I want to combine some classes for the convenience of cascading appropriate styling. I could simply replicate the styling in a single class but I am assuming that that would be bad practice.
<div class="left_Item drop_Down" id="col_1">some stuff</div>
$(".left_Item, .drop_Down#col_1").whatever....;
// matches every occurrence of class left_Item with the single occurrence of //drop_Down#col_1 ... this tallies with the multiple selector documentation.
$("#col_1").whatever....;
//obviously does match as the selector is only looking at the id.
//however
$(".drop_Down#col_1").whatever....;
//does not match Does this imply that the classes cannot be matched separately? So....
$(".left_Item.drop_Down#col_1").whatever....;
// various posts on so state that this should match it does not for me. Nor does
$(".left_Item .drop_Down#col_1").whatever....;
$(".left_Item").filter(".drop_Down#col_1).whatever....;
// various posts on so state that this should match also but it does not for me.
So firstly I assume that I am doing the correct thing using multiple classes. If not I'll stop trying to make this work!
Secondly please can some one give the correct jquery syntax to match an element with multiple classes.
Thx
The syntax is as follows (for CSS or jQuery):
.class1.class2
In your case:
$(".left_Item.drop_Down").whatever...
If you want to use an id as well as a class selector, then put the id first:
$("#col_1.left_Item.drop_Down")
Though since ids are supposed to be unique, I don't understand why you don't just use $("#col_1")
If the classes are your main focus then try this.
$('.left_Item.drop_Down').whatever...
But if you want an Id that has classes left_Item drop_Down you might do this
$('#col_1.left_Item.drop_Down').whatever...