XML/XPath: Difference between revisions

m
Corrected typo. Modified general comment.
(Replaced the wrong solution with a solution which uses "libxml2" as external library.)
m (Corrected typo. Modified general comment.)
Line 2,476:
Nim standard library provides several modules to process XML, but none to process XPath requests. There is no third party library to do that either.
 
So we provide here a solution which uses the C "libxml2" library. Nim allows to interface with C with a great flexibility. Declaring the external functionfunctions is quite easy. The major part of the work consists into declaringdeclare the data types. In "libxml2" there are a lot of structures and we have translated only what is needed to solve the task (or actually a bit more actually).
 
For the first request, we use <code>//section[1]/item[1]</code> instead of <code>//item[1]</code> (asthis is also what the Python version does). The latter request works but returnsit the list ofreturns the first elementselement in each section which doesn’t seem to be what is expected.
 
<lang Nim>import sequtils, strutils
Anonymous user