| Link | xml_nodemap |
| Author | Jason Huck |
| Category | XML |
| Version | 8.5.x |
| License | Public Domain |
| Posted | 01 Jun 2007 |
| Updated | 01 Jun 2007 |
| More by this author... | |
When working with basic XML documents that do not have complex nested structures, it can sometimes be handy to extract a map of all the node names and their text values. This tag is a shortcut for that. It returns a map of every node that contains at least one non-empty text value.
[//lasso
var('data') = string('\
-
1
red
small
9.99
\
');
xml_nodemap($data);
]
Returns:
map: (Price)=(9.99), (Size)=(small), (Quantity)=(1), (Color)=(red)
Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.
define_tag(
'nodemap',
-namespace='xml_',
-req='in', -copy,
-priority='replace',
-description='Returns a flattened map of node values from XML.'
);
#in->type != 'xml' ? #in = xml(string(#in));
local('out' = map);
iterate(#in->extract('//*'), local('i'));
if(#i->extract('text()')->size);
local(
'name' = @#i->extract('local-name()'),
'value' = string(#i->extract('text()')->first)->trim&
);
#value->size ? #out->insert(#name = #value);
/if;
/iterate;
return(#out);
/define_tag;
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft