Hello. I'm working on a migration from ACF to Luce...
# cfml-general
j
Hello. I'm working on a migration from ACF to Lucee. The app I'm testing uses SerializeXML which is not supported by Lucee. I've tried Lucee's Serialize now I'm overflowing the stack ugh. Any ideas? Thanks
s
Copy code
/**
	*  @param input      Data to convert into XML. (Required)
 	* @param element      Used to name the root element. (Required)
	* @param attributeMeta Checks for the presence of a key in attributeMeta when rendering the key in input, and writes out the contents as attribute/value pairs for the corresponding key
 	* @return Returns a string. 
 	* @author Phil Arnold (<mailto:philip.r.j.arnold@googlemail.com|philip.r.j.arnold@googlemail.com>) with modifications by Samuel Knowlton (<mailto:sam@inleague.io|sam@inleague.io>) - removed lcasing and added support for attributeMeta
 	* @version September 9, 2009 / September 29, 2021 
 	**/
   
	public string function toXML( required input, required string element, struct attributeMeta = {} ) {
		var i = 0;
		var s = createObject( "java", "java.lang.StringBuilder" ).init()
		var s1 = "";
		s1 = arguments.element;
		if ( right( s1, 1 ) eq "s" ) {
			s1 = left( s1, len( s1 ) - 1 );
		}

		s.append( renderXMLAttribute( arguments.element, arguments.attributeMeta ) );
		if ( isArray( arguments.input ) ) {
			for ( i = 1; i lte arrayLen( arguments.input ); i = i + 1 ) {
				if ( isSimpleValue( arguments.input[ i ] ) ) {
					s.append( renderXMLAttribute( s1, attributeMeta ) & arguments.input[ i ] & "</#s1#>" );
				}
				else {
					s.append( toXML( arguments.input[ i ], s1 ) );
				}
			}
		}
		else if ( isStruct( arguments.input ) ) {
			for ( i in arguments.input ) {
				if ( isSimpleValue( arguments.input[ i ] ) ) {
					s.append( renderXMLAttribute( i, attributeMeta ) & arguments.input[ i ] & "</#i#>" );
				}
				else {
					s.append( toXML( arguments.input[ i ], i ) );
				}
			}
		}
		else {
			s.append( xmlFormat( arguments.input ) );
		}
		s.append( "</#arguments.element#>" );

		return s.toString();
	}

	/**
	 * renderXMLAttribute
	 * @hint A totally low-rent way to render out XML attributes (e.g. <foo bar="baz">) by checking for the presence of the key in a "sister struct" containing attribute meta nodes. Can't handle multiple nodes with the same name.
	 * @return String OPENING attribute only (e.g. just <foo bar="baz">)
	 */

	public string function renderXMLAttribute( required string key, required struct attributeMeta ) {
		var attr = '<#arguments.key#';
		if ( attributeMeta.keyExists( arguments.key ) ) {
			for ( var metaKey in arguments.attributeMeta[ arguments.key ].keyArray() ) {
				attr &= ' #metaKey#="' & arguments.attributeMeta[ arguments.key ][ metaKey ] & '"';
			}
		}
		attr &= '>';
		return attr;
	}
🙌 1
b
@Joe Dickson Please don't cross-post the same question in multiple channels. https://cfml.slack.com/archives/C06TA0A9W/p1670866192400699