@@ -29,7 +29,9 @@ The following functions are exported from `xmpp` module:
29
29
- [ get_els/1] ( #get_els1 )
30
30
- [ set_els/2] ( #set_els2 )
31
31
- [ get_subtag/2] ( #get_subtag2 )
32
+ - [ get_subtags/2] ( #get_subtags2 )
32
33
- [ try_subtag/2] ( #try_subtag2 )
34
+ - [ try_subtags/2] ( #try_subtags2 )
33
35
- [ set_subtag/2] ( #set_subtag2 )
34
36
- [ remove_subtag/2] ( #remove_subtag2 )
35
37
- [ has_subtag/2] ( #has_subtag2 )
@@ -225,7 +227,7 @@ during lazy decoding only top-level element is decoded.
225
227
226
228
** Example 2** : full decoding
227
229
``` erlang
228
- > xmpp :decode (El , <<" jabber:client" >>, []).
230
+ > xmpp :decode (El , <<" jabber:client" >>, []).
229
231
# message {id = <<>>,type = normal ,lang = <<>>,
230
232
from = undefined ,to = undefined ,subject = [],body = [],
231
233
thread = undefined ,
@@ -240,15 +242,15 @@ sub-elements (`<foo/>` in our case) remain untouched.
240
242
241
243
** Example 3** : no namespace is provided and ` El ` doesn't possess any
242
244
``` erlang
243
- > xmpp :decode (El , <<>>, []).
245
+ > xmpp :decode (El , <<>>, []).
244
246
** exception error : {xmpp_codec ,{missing_tag_xmlns ,<<" message" >>}}
245
247
in function xmpp_codec :decode / 3 (src / xmpp_codec .erl , line 16 )
246
248
```
247
249
It is safe to apply the function to ` xmpp_element() ` :
248
250
249
251
** Example 4** : double decoding
250
252
``` erlang
251
- > xmpp :decode (xmpp :decode (El , <<" jabber:client" >>, [])).
253
+ > xmpp :decode (xmpp :decode (El , <<" jabber:client" >>, [])).
252
254
# message {id = <<>>,type = normal ,lang = <<>>,
253
255
from = undefined ,to = undefined ,subject = [],body = [],
254
256
thread = undefined ,
@@ -389,7 +391,7 @@ of an `xmlel()` element.
389
391
390
392
** Example 1** : obtaining ` type ` of ` presence() `
391
393
``` erlang
392
- > xmpp :get_type (# presence {}).
394
+ > xmpp :get_type (# presence {}).
393
395
available
394
396
```
395
397
** Example 2** : obtaining ` type ` of ` xmlel() `
@@ -408,7 +410,7 @@ Sets `type` field of a `stanza()`.
408
410
409
411
** Example 1** : setting ` type ` field of ` message() `
410
412
``` erlang
411
- > xmpp :set_type (# message {}, chat ).
413
+ > xmpp :set_type (# message {}, chat ).
412
414
# message {id = <<>>,type = chat ,lang = <<>>,from = undefined ,
413
415
to = undefined ,subject = [],body = [],thread = undefined ,
414
416
sub_els = [],meta = #{}}
@@ -456,7 +458,7 @@ Returns a value of `from` field of a `stanza()`.
456
458
457
459
** Example 1** : obtaining ` from ` of ` message() `
458
460
``` erlang
459
- > xmpp :get_from (# message {from = jid :decode (<<" user@server/resource" >>)}).
461
+ > xmpp :get_from (# message {from = jid :decode (<<" user@server/resource" >>)}).
460
462
# jid {user = <<" user" >>,server = <<" server" >>,
461
463
resource = <<" resource" >>,luser = <<" user" >>,
462
464
lserver = <<" server" >>,lresource = <<" resource" >>}
@@ -500,7 +502,7 @@ Returns a value of `to` field of a `stanza()`.
500
502
501
503
** Example 1** : obtaining ` to ` of ` message() `
502
504
``` erlang
503
- > xmpp :get_to (# message {to = jid :decode (<<" user@server/resource" >>)}).
505
+ > xmpp :get_to (# message {to = jid :decode (<<" user@server/resource" >>)}).
504
506
# jid {user = <<" user" >>,server = <<" server" >>,
505
507
resource = <<" resource" >>,luser = <<" user" >>,
506
508
lserver = <<" server" >>,lresource = <<" resource" >>}
@@ -532,7 +534,7 @@ Sets `to` field of a `stanza()`.
532
534
```
533
535
** Example 2** : removing ` to ` value from ` iq() `
534
536
``` erlang
535
- > xmpp :set_to (# iq {to = jid :decode (<<" user@server/resource" >>)}, undefined ).
537
+ > xmpp :set_to (# iq {to = jid :decode (<<" user@server/resource" >>)}, undefined ).
536
538
# iq {id = <<>>,type = undefined ,lang = <<>>,from = undefined ,
537
539
to = undefined ,sub_els = [],meta = #{}}
538
540
```
@@ -668,6 +670,12 @@ as show in the following example.
668
670
# ping {}
669
671
```
670
672
673
+ ## get_subtags/2
674
+ ``` erlang
675
+ -spec get_subtags (Stanza :: stanza (), Tag :: xmpp_element ()) -> [xmpp_element ()].
676
+ ```
677
+ Same as ` get_subtag/2 ` , but returns all elements matching ` Tag ` , preserving their original order.
678
+
671
679
## try_subtag/2
672
680
``` erlang
673
681
-spec try_subtag (Stanza :: stanza (), Tag :: xmpp_element ()) -> xmpp_element () | false .
@@ -689,6 +697,12 @@ false
689
697
** exception error : {xmpp_codec ,{missing_attr ,<<" id" >>,<<" iq" >>, <<" jabber:client" >>}}
690
698
```
691
699
700
+ ## try_subtags/2
701
+ ``` erlang
702
+ -spec try_subtags (Stanza :: stanza (), Tag :: xmpp_element ()) -> [xmpp_element ()].
703
+ ```
704
+ Same as ` try_subtag/2 ` , but returns all elements matching ` Tag ` , preserving their original order.
705
+
692
706
## set_subtag/2
693
707
``` erlang
694
708
-spec set_subtag (Stanza :: iq (), Tag :: xmpp_element ()) -> iq ();
@@ -963,7 +977,7 @@ metadata of `Stanza`.
963
977
964
978
** Example 1** : sets new key in metadata
965
979
``` erlang
966
- > xmpp :put_meta (# presence {}, foo , bar ).
980
+ > xmpp :put_meta (# presence {}, foo , bar ).
967
981
# presence {id = <<>>,type = available ,lang = <<>>,
968
982
from = undefined ,to = undefined ,show = undefined ,
969
983
status = [],priority = undefined ,sub_els = [],
@@ -995,7 +1009,7 @@ Fails with `{badkey,Key}` exception if no value is associated with `Key`.
995
1009
```
996
1010
** Example 2** : updating non-existing key
997
1011
``` erlang
998
- > xmpp :update_meta (# presence {}, foo , bar ).
1012
+ > xmpp :update_meta (# presence {}, foo , bar ).
999
1013
** exception error : {badkey ,foo }
1000
1014
...
1001
1015
```
@@ -1009,7 +1023,7 @@ metadata of `Stanza`.
1009
1023
1010
1024
** Example 1** : removing value by key
1011
1025
``` erlang
1012
- > xmpp :del_meta (# presence {meta = #{foo => bar }}, foo ).
1026
+ > xmpp :del_meta (# presence {meta = #{foo => bar }}, foo ).
1013
1027
# presence {id = <<>>,type = available ,lang = <<>>,
1014
1028
from = undefined ,to = undefined ,show = undefined ,
1015
1029
status = [],priority = undefined ,sub_els = [],meta = #{}}
@@ -1061,12 +1075,12 @@ true
1061
1075
```
1062
1076
** Example 2** : the tag is unknown
1063
1077
``` erlang
1064
- > xmpp :is_known_tag (# xmlel {name = <<" foo" >>, attrs = [{<<" xmlns" >>,<<" bar" >>}]}).
1078
+ > xmpp :is_known_tag (# xmlel {name = <<" foo" >>, attrs = [{<<" xmlns" >>,<<" bar" >>}]}).
1065
1079
false
1066
1080
```
1067
1081
** Example 3** : the element lacks namespace, so it's always unknown
1068
1082
``` erlang
1069
- > xmpp :is_known_tag (# xmlel {name = <<" x" >>}).
1083
+ > xmpp :is_known_tag (# xmlel {name = <<" x" >>}).
1070
1084
false
1071
1085
```
1072
1086
** Example 4** : the element lacks namespace, but we assume it's within 'jabber: server ' namespace
@@ -1083,7 +1097,7 @@ Returns namespace of `xmpp_element()` or `xmlel()` element.
1083
1097
1084
1098
** Example 1** : obtaining namespace of ` xmpp_element() `
1085
1099
``` erlang
1086
- > xmpp :get_ns (# disco_info {}).
1100
+ > xmpp :get_ns (# disco_info {}).
1087
1101
<<" http://jabber.org/protocol/disco#info" >>
1088
1102
```
1089
1103
** Example 2** : obtaining namespace of ` xmlel() ` element
@@ -1129,7 +1143,7 @@ Creates from `IQ` an `iq()` of type `result` with empty sub-elements.
1129
1143
** Example 2** : trying to create a result of a result
1130
1144
``` erlang
1131
1145
> xmpp :make_iq_result (# iq {type = result , id = <<" 1" >>}).
1132
- ** exception error : no function clause matching
1146
+ ** exception error : no function clause matching
1133
1147
```
1134
1148
1135
1149
## make_iq_result/2
@@ -1154,7 +1168,7 @@ Creates from `IQ` an `iq()` of type `result` with sub-elements set to `[El]`.
1154
1168
** Example 2** : trying to create a result of a result
1155
1169
``` erlang
1156
1170
> xmpp :make_iq_result (# iq {type = result , id = <<" 1" >>}, # disco_items {}).
1157
- ** exception error : no function clause matching
1171
+ ** exception error : no function clause matching
1158
1172
```
1159
1173
1160
1174
## make_error/2
@@ -1180,7 +1194,7 @@ Constructs `stanza()` of type `error` from `Stanza`.
1180
1194
** Example 2** : trying to create an error from an error
1181
1195
``` erlang
1182
1196
> xmpp :make_error (# presence {type = error }, xmpp :err_bad_request ()).
1183
- ** exception error : no function clause matching
1197
+ ** exception error : no function clause matching
1184
1198
```
1185
1199
1186
1200
## get_error/1
@@ -1205,7 +1219,7 @@ if not found of if decoding has failed.
1205
1219
```
1206
1220
** Example 2** : no ` stanza_error() ` element found
1207
1221
``` erlang
1208
- > xmpp :get_error (# message {}).
1222
+ > xmpp :get_error (# message {}).
1209
1223
undefined
1210
1224
```
1211
1225
@@ -1220,7 +1234,7 @@ or [decode/3](#decode3).
1220
1234
``` erlang
1221
1235
> try xmpp :decode (# xmlel {name = <<" foo" >>})
1222
1236
catch _ :{xmpp_codec , Reason } -> xmpp :format_error (Reason )
1223
- end .
1237
+ end .
1224
1238
<<" Unknown tag <foo/> qualified by namespace 'jabber:client'" >>
1225
1239
> try xmpp :decode (# xmlel {name = <<" iq" >>})
1226
1240
catch _ :{xmpp_codec , Reason } -> xmpp :format_error (Reason )
@@ -1334,7 +1348,7 @@ Pretty printer for XMPP elements.
1334
1348
1335
1349
** Example** :
1336
1350
``` erlang
1337
- > S = xmpp :pp (# sm_a {h = 10 , xmlns = <<" urn:xmpp:sm:3" >>}).
1351
+ > S = xmpp :pp (# sm_a {h = 10 , xmlns = <<" urn:xmpp:sm:3" >>}).
1338
1352
[" #sm_a" ,123 ,
1339
1353
[[" h" ," = " ,49 ,48 ],
1340
1354
44 ,
@@ -2166,7 +2180,7 @@ a valid timestamp.
2166
2180
```
2167
2181
** Example 3** : decoding failure - not even remotely a timestamp
2168
2182
``` erlang
2169
- > xmpp_util :decode_timestamp (<<" sd324klsjdpsdf" >>).
2183
+ > xmpp_util :decode_timestamp (<<" sd324klsjdpsdf" >>).
2170
2184
** exception error : {bad_timestamp ,<<" sd324klsjdpsdf" >>}
2171
2185
...
2172
2186
```
@@ -2421,7 +2435,7 @@ Returns `error` if stringprep has failed.
2421
2435
```
2422
2436
** Example 3** : stringprep failure
2423
2437
``` erlang
2424
- > jid :tolower ({<<" @" >>, <<" Server" >>, <<" Resource" >>}).
2438
+ > jid :tolower ({<<" @" >>, <<" Server" >>, <<" Resource" >>}).
2425
2439
error
2426
2440
```
2427
2441
0 commit comments