Erlang/OTP Forums

Author Message

<  Erlang questions mailing list  ~  xmerl question

Guest
Posted: Sun Jul 22, 2007 5:05 am Reply with quote
Guest
Hi,

I am not getting a match correct...

For the #xmlElement like:

<matchup kickoff="1189125000" gameSecondsRemaining="3600">
<team id="NOS" isHome="0" score=""/>
<team id="IND" isHome="1" score=""/>
</matchup>

I'm trying to parse it with:

parse_matchup(Matchup) ->
#xmlElement{attributes=Attribs, content=Content} = Matchup,
[ #xmlAttribute{name=kickoff, value=Kickoff} ] = Attribs,
Kickoff.


I'm getting a badmatch [1] when I try to get the value of the 'kickoff'
attribute. Any idea what I'm doing wrong?

I used

Matchups = [parse_matchup(M) || M <- xmerl_xpath:string("//matchup", Xml)],

to send Matchup to the fn, but I didn't want to keep using xpath on each
attrib and child node, because of efficiency. Should I not worry about
that?

Cheers,
BA



[1]

=ERROR REPORT==== 22-Jul-2007::00:56:55 ===
Error in process <0.341.0> with exit value:
{{badmatch,[{xmlAttribute,kickoff,[],[],[],[],1,[],"1189125000",fals\e},{xmlAttribute,gameSecondsRemaining,[],[],[],[],2,[],"3600",false}]},[{schedule,parse_matchup,1},{erl_eval,do_\apply,5},{shell,exprs,6},{shell,eval_loop,3}]}

** exited: {{badmatch,[{xmlAttribute,kickoff,
[],
[],
[],
[],
1,
[],
"1189125000",
false},
{xmlAttribute,gameSecondsRemaining,
[],
[],
[],
[],
2,
[],
"3600",
false}]},
[{schedule,parse_matchup,1},
{erl_eval,do_apply,5},
{shell,exprs,6},
{shell,eval_loop,3}]} **


_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist
Guest
Posted: Sun Jul 22, 2007 8:24 am Reply with quote
Guest
Brad Anderson-3 wrote:
>
> Hi,
>
> I am not getting a match correct...
>
> For the #xmlElement like:
>
> <matchup kickoff="1189125000" gameSecondsRemaining="3600">
> <team id="NOS" isHome="0" score=""/>
> <team id="IND" isHome="1" score=""/>
> </matchup>
>
> I'm trying to parse it with:
>
> parse_matchup(Matchup) ->
> #xmlElement{attributes=Attribs, content=Content} = Matchup,
> [ #xmlAttribute{name=kickoff, value=Kickoff} ] = Attribs,
> Kickoff.
>
>
> I'm getting a badmatch [1] when I try to get the value of the 'kickoff'
> attribute. Any idea what I'm doing wrong?
>

In that particular instance of xml you have multiple attributes, so the
pattern match would need to be something along the lines of:

[#xmlAttribute{name=kickoff, value=Kickoff}|_] = Attribs,

but be aware this way depends on the kickoff attribute being first in the
element so its still pretty fragile.

--
View this message in context: http://www.nabble.com/xmerl-question-tf4124134.html#a11729169
Sent from the Erlang Questions mailing list archive at Nabble.com.

_______________________________________________
erlang-questions mailing list
erlang-questions@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-questions
Post recived from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum