Lasso Soft Inc. > Home

[xml_nodemap]

Linkxml_nodemap
AuthorJason Huck
CategoryXML
Version8.5.x
LicensePublic Domain
Posted01 Jun 2007
Updated01 Jun 2007
More by this author...

Description

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.

Sample Usage

[//lasso
	var('data') = string('\

	
	
		
			1
			red
			small
			9.99
		
	
\
	');
	
	xml_nodemap($data);
]

Returns:

map: (Price)=(9.99), (Size)=(small), (Quantity)=(1), (Color)=(red)

Source Code

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;

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft