[erlang-questions] xmerl_xpath difficulties

Jeremy Thurgood jerith@REDACTED
Sun Aug 5 15:07:41 CEST 2007


David Mitchell wrote:

> I'm having trouble getting my head around xmerl_xpath - I've gone
> through a bunch of Google searches, but can't find the "Simple guide
> to xmerl_xpath" I'm looking for ;->

You might want to look at the W3C's xpath tutorial at 
http://www.w3schools.com/xpath/default.asp

> I've reduced my problem to 3 lines of code:
> 
> 15> {XmlFull, _} = xmerl_scan:string("<text>Hello</text>").
> {{xmlElement,text,
>              text,
>              [],
>              {xmlNamespace,[],[]},
>              [],
>              1,
>              [],
>              [{xmlText,[{text,1}],1,[],"Hello",text}],
>              [],
>              "/home/davidm",
>              undeclared},
>  []}
> 
> 16> xmerl:export([XmlFull], xmerl_xml).
> ["<?xml version=\"1.0\"?>",[[["<","text",">"],["Hello"],["</","text",">"]]]]
> 
> 17> xmerl_xpath:string("//text/*", XmlFull).
> []
> 
> 
> Line 16 seems to confirm that XmlFull contains my XML string.
> However, I'd expect line 17 to give me something like "Hello" or
> ["Hello"], yet it returns an empty list.

You're asking it for xml elements below <text>, of which there are none.

5> xmerl_xpath:string("//text/text()", XmlFull).
[{xmlText,[{text,1}],1,[],"Hello",text}]

Look like you'll still have to extract the string from the #xmlText record.

HTH,
--J



More information about the erlang-questions mailing list