SweetXml.sigil_x
sigil_x
, go back to SweetXml module for more information.
sigil_x/2
simply returns a %SweetXpath{}
struct, with modifiers converted to
boolean fields:
iex> SweetXml.sigil_x("//some/path", 'e')
%SweetXpath{path: '//some/path', is_value: false, cast_to: false, is_list: false, is_keyword: false}
Or you can simply import and use the ~x
expression:
iex> import SweetXml
iex> ~x"//some/path"e
%SweetXpath{path: '//some/path', is_value: false, cast_to: false, is_list: false, is_keyword: false}
Valid modifiers are e
, s
, l
and k
. Below is the full explanation
~x"//some/path"
without any modifiers,
xpath/2
will return the value of the entity if the entity is of typexmlText
,xmlAttribute
,xmlPI
,xmlComment
as defined in:xmerl
~x"//some/path"e
e
stands for (e)ntity. This forcesxpath/2
to return the entity with which you can further chain yourxpath/2
call~x"//some/path"l
'l' stands for (l)ist. This forces
xpath/2
to return a list. Withoutl
,xpath/2
will only return the first element of the match~x"//some/path"el
- mix of the above~x"//some/path"k
'k' stands for (K)eyword. This forces
xpath/2
to return a Keyword instead of a Map.~x"//some/path"s
's' stands for (s)tring. This forces
xpath/2
to return the value as string instead of a char list.x"//some/path"o
'o' stands for (O)ptional. This allows the path to not exist, and will return nil.
~x"//some/path"sl
- string list.~x"//some/path"i
'i' stands for (i)nteger. This forces
xpath/2
to return the value as integer instead of a char list.~x"//some/path"f
'f' stands for (f)loat. This forces
xpath/2
to return the value as float instead of a char list.~x"//some/path"il
- integer list