Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
dev:technologies [2011/07/23 10:43] – [Regular Expressions] ajlyon | dev:technologies [2017/12/12 04:56] (current) – removed sean | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | A very brief introduction to some commonly used technologies used in translator development. | ||
- | ====== XPath ====== | ||
- | XPath provides a way to refer to specific parts of HTML or XML documents. It's usually the best way to extract data from webpages when writing a translator. | ||
- | |||
- | An XPath expression is a chain of pieces that specify the path to a node of the document. The main pieces of expressions are: | ||
- | |||
- | * ''/'' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * Plus much more. See the [[http:// | ||
- | |||
- | The best introduction to XPath for use in translators is Mozilla' | ||
- | |||
- | === Examples === | ||
- | <code html> | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | < | ||
- | </ | ||
- | < | ||
- | <tr class=" | ||
- | < | ||
- | < | ||
- | </tr> | ||
- | </ | ||
- | </ | ||
- | </ | ||
- | </ | ||
- | For the sample document above, these expressions would refer to... | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | |||
- | === Using Firebug to design XPath expressions === | ||
- | |||
- | To make it easier to design XPath expressions, | ||
- | |||
- | First, install Firebug and restart Firefox. You'll see a bug icon at the bottom right hand side of your browser window: | ||
- | |||
- | {{firebug2.png|}} | ||
- | |||
- | {{firebug1.png|}} | ||
- | |||
- | Click the icon to open the Firebug pane, which will show lots of details about the current page: | ||
- | |||
- | {{firebug3.png}} | ||
- | |||
- | Next, click the " | ||
- | |||
- | {{firebug4.png}} | ||
- | |||
- | Firebug will highlight the part of the web page's code that corresponds to the location you clicked on. Right-click on that piece of code in the Firebug pane and select "Copy XPath" | ||
- | |||
- | Then we can paste the XPath expression into the editor (i.e., the code pane of [[dev: | ||
- | |||
- | < | ||
- | / | ||
- | </ | ||
- | |||
- | XPath like this, however, is very fragile. It's better to latch onto some identifiers and make an expression relative to them: | ||
- | < | ||
- | // | ||
- | </ | ||
- | |||
- | ====== Regular Expressions ====== | ||
- | Regular expressions are a way of matching and extracting pieces of text from a larger body of text. In translator development, | ||
- | |||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * '' | ||
- | * ''?'' | ||
- | |||
- | For a complete description of how regular expressions are used in JavaScript, with examples of their use, see Mozilla' | ||
- | |||
- | There are many regular expressions guides on the web, and entire books on the topic. While you can and should consult these guides, keep in mind that the details of how they work will depend a little on the environment they' |