Miva Merchant Modules and Development
Want to start an online store? We work with you from start to finish, from commerce platform to design to SEO.
Experience counts, and we have a lot.

MIVASCRIPT: Parse Any Tag

Scot Ranney • December 19, 2023


Parse xml or tag or whatever is in between matching <xx> ... </xx>

To parse data between a div tag, start would be <div> and end would be </div>

Perfectly useless except in very specific situations.

<MvFUNCTION NAME = "parse_features" PARAMETERS = "data,start,end" STANDARDOUTPUTLEVEL="">
	<MvIF EXPR = "{NOT l.data}">
		<MvFUNCRETURN VALUE = "{ '' }">
	</MvIF>


	<MvWHILE EXPR = "{'<feature>' CIN l.data}">
				<MvASSIGN NAME = "l.counter" VALUE = "{ ++l.counter }" />
		<MvIF EXPR = "{l.start CIN l.data AND l.end CIN l.data}">
			<MvASSIGN NAME = "l.block"  VALUE = "{substring(l.data,(l.start CIN l.data) ,(l.end ECIN l.data) - (l.start CIN l.data) +5)}">
			<MvASSIGN NAME = "l.original" VALUE = "{ l.block }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ get_block_data(l.block,'name' ,1,l.fulltag,l.feature:name) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ get_block_data(l.block,'code' ,1,l.fulltag,l.feature:code) }">
			<MvASSIGN NAME = "l.ok" VALUE = "{ get_block_data(l.block,'notes',1,l.fulltag,l.feature:notes) }">
			<MvASSIGN NAME = "l.mfpos" VALUE = "{ 0 }">
			<MvASSIGN NAME = "l.mfs" VALUE = "{ '' }">
			<MvWHILE EXPR = "{'<mf>' CIN l.block}">
						<MvASSIGN NAME = "l.mfstart" VALUE = "{ '<mf>' }">
						<MvASSIGN NAME = "l.mfend" VALUE = "{ '</mf>' }">
				<MvIF EXPR = "{l.mfstart CIN l.block AND l.mfend CIN l.block}">
					<MvASSIGN NAME = "l.mf"  VALUE = "{substring(l.block,(l.mfstart CIN l.block) ,(l.mfend ECIN l.block) - (l.mfstart CIN l.block) +4)}">
								<MvASSIGN NAME = "l.ok" VALUE = "{ get_block_data(l.mf,'name', 1,l.fulltag,l.mfinfo:name) }">
				<MvASSIGN NAME = "l.mfinfo:vars" VALUE = "{ trim(gettoken(l.mfinfo:name,'(',2)) }">
				<MvASSIGN NAME = "l.mfinfo:vars" VALUE = "{ trim(substring(l.mfinfo:vars,1,len(l.mfinfo:vars) - 1)) }">
				<MvASSIGN NAME = "l.mfinfo:name" VALUE = "{ trim(gettoken(l.mfinfo:name,'(',1)) }">
				<MvASSIGN NAME = "l.ok" VALUE = "{ get_block_data(l.mf,'notes',1,l.fulltag,l.mfinfo:notes) }">
				<MvASSIGN NAME = "l.mfs" INDEX = "{ ++l.mfpos }" VALUE = "{ l.mfinfo }">
				<MvASSIGN NAME = "l.block" VALUE = "{ glosub(l.block,l.mf,'') }">
				</MvIF>
			</MvWHILE>
			<MvASSIGN NAME = "l.feature:mfs" VALUE = "{ l.mfs }">
			<MvASSIGN NAME = "l.data" VALUE = "{ glosub(l.data,l.original,'') }">
		</MvIF>
		<MvASSIGN NAME = "l.features" INDEX = "{ ++l.pos3 }" VALUE = "{ l.feature }">
	</MvWHILE>
	<MvFUNCRETURN VALUE = "{ l.features }">
<MvCOMMENT>
|--------------------------------
|	debug:

	<MvEVAL EXPR = "{debugarray(l.features)}">
|--------------------------------
</MvCOMMENT>
</MvFUNCTION>

<MvFUNCTION NAME = "get_block_data" PARAMETERS = "data,tag,offset,fulltag var,datatag var" STANDARDOUTPUTLEVEL="">
	<MvASSIGN NAME = "l.open" VALUE = "{ '<' $ l.tag $ '>' }">
	<MvASSIGN NAME = "l.close" VALUE = "{ '</' $ l.tag $ '>' }">
	<MvASSIGN NAME = "l.start" VALUE = "{ (l.open CIN l.data) }">
	<MvASSIGN NAME = "l.end" VALUE = "{ l.close ECIN l.data }">
	<MvASSIGN NAME = "l.datastart" VALUE = "{ (l.open ECIN l.data) + 1}">
	<MvASSIGN NAME = "l.dataend" VALUE = "{ l.close CIN l.data }">
	<MvASSIGN NAME = "l.fulltag" VALUE = "{ substring(l.data,l.start,l.end - l.start + 1) }">
	<MvASSIGN NAME = "l.datatag" VALUE = "{ trim(substring(l.data,l.datastart,l.dataend - l.datastart)) }">
</MvFUNCTION>

https://www.scotsscripts.com/mvblog/mivascript-parse-any-tag.html

mvkb