XML Header - Special Characters

Hello. I’m trying to product the following output: (the values aren’t important…the format is)






<USER_DATA_2>360 VT Tech Ltd</USER_DATA_2>




The problem is in the and tag part...I cannot get it to allow special characters such as the = or quotes between the < and >... I get:

ERROR: The ‘=’ character, hexadecimal value 0x3D, cannot be included in a name.

Here’s my code:

//concatenate line in XML

fileStr =

“file_id=’”+BatchLogTable.fileid+"’ file_total_amount=’"+num2str(myView.AmountCur,0,2,1,0)+"’ file_tran_count=’"+num2str(myView.RecId,0,0,1,0)+"’";

//concatenate line in XML

batchStr =


//start creation of XML

doc = XmlDocument::newBlank();

nodeFile = doc.createElement(fileStr



nodeBatch = doc.createElement(batchStr);


Everything after this works, so I didn’t include it. If I remove the single quotes and equal signs from the fileStr and batchStr values, I don’t get the error, but I need those so they can be read on the other end.

Any ideas?


It’s because createElement() expects a name of an element, therefore the whole string you provided is interpreted as element’s name and characters as ‘=’ are not allowed there. But the name is wrong. The name is “FILE”, not *"*FILE file_id=“20140318A” file_total_amount=“1945.00” file_tran_count=“10” (for example). Use setAttribute() to add attributes to an element.

Thanks for your help…I actually came to same conclusion after posting this. This was the first time I dealt with trying to create an XML, so I had trouble with my syntax when trying to use the setAttribute(), but I finally got it figured out. I was over-thinking it.

Here’s a simplified sample of my code for anyone else looking for same solution, since there’s not a lot of examples I found out there…

Create a new class and create this as the main method:

public static void main(Args _args)


//declare variables

XmlDocument doc;

XmlElement nodeFile;

XmlElement nodeBatch;

XmlElement nodeTable;

XmlElement nodeAccount;

XmlElement nodeAmount;

str myFileName;

CustTransView myView;

date currDate;

//define file path and name


//data used for my example

currDate = systemDateGet();

select sum(AmountCur),count(recid) from myView where myView.TransDate == currDate;

myFileName = ‘Sample.xml’;

//start creation of XML

doc = XmlDocument::newBlank();

//FILE Node

nodeFile = doc.createElement(‘File’);


//will display Total AmountCur and Total # of records from myView in node (from previous sql select)




//BATCH Node

nodeBatch = doc.createElement(‘Batch’);

//uses date as the batch id to display in node




While select myView where myView.TransDate == currDate


//display Account and Amount for each record in the node

nodeTable = doc.createElement(“DETAIL”);


nodeAccount = doc.createElement(“Account_Num”);



nodeAmount = doc.createElement(“AMOUNT”);




//save XML to path


//display completion message

info(strFmt(“File %1 created.”, #filename));