xmerl and selecting attributes
Ralf Doering
rdoering@REDACTED
Tue Sep 8 12:21:31 CEST 2009
Hello,
seems I've got a problem selecting the value of an attribute from an XML tag.
Consider the following short example:
--8<---------------cut here---------------start------------->8---
-module(xmerl_test).
-include_lib("xmerl/include/xmerl.hrl").
-import(xmerl_xs,
[ xslapply/2, value_of/1, select/2, built_in_rules/2 ]).
-export([start/0]).
start() ->
{XmlElement, _Rest} = xmerl_scan:string("<test myattr=\"123\" />"),
template(XmlElement).
template( E = #xmlElement{name='test'}) ->
Attr = value_of(select("@myattr", E)),
io:format("MyAttribute: ~w~n", [Attr]),
xslapply(fun template/1,E),
E;
template(E) ->
built_in_rules( fun template/1, E).
--8<---------------cut here---------------end--------------->8---
When running this, I get:
(emacs@REDACTED)13> xmerl_test:start().
MyAttribute: []
[]
I was expecting that value_of(select("@myattr"),E) would extract "123" as
attribute value. Am I wrong here, do I use the wrong XPath for this?
TIA,
Ralf
--
Ralf Döring | NetSys.IT GbR
Networking & Security Solutions | www.netsys-it.de
rdoering@REDACTED | Tel.: +49 (3677) 20 35 15
More information about the erlang-questions
mailing list