Massaging invalid XML into valid XML using javascript and/or jquery

tutan

New Member
I have a text box prompt where people submit XML-type markup for actions to be undertaken.My objective is to be fairly tolerant of user input and not force them to adhere to strict XML standards. Rather, I would want to take their input and massage into a valid XML that I would pass to the server.An example to illustrate:valid XML document is\[code\]<Actions> <Action do="this"/> <Action do="that"/> <Action do="theother"/></Actions>\[/code\]Users might input the following (invalid) XML into the text box:\[code\]<Actions> <Action do="this"/> <Action do="that"/> <Action do="theother"/> <!-- Oh hello --></Actions> <Action do="that"/> <Action do="thatagain"/><Actions> <Action do="thatagainreally"/></Actions>\[/code\]I would want to tolerate such input and on the client, using javascript or jquery, transform it to\[code\]<Actions> <Action do="this"/> <Action do="that"/> <Action do="theother"/> <Action do="that"/> <Action do="thatagain"/> <Action do="thatagainreally"/></Actions>\[/code\]My approach is to take the text input -- wrap it in some randomly generated tag such as:\[code\]<sadfasdf> <Actions> <Action do="this"/> <Action do="that"/> <Action do="theother"/> <!-- Oh hello --> </Actions> <Action do="that"/> <Action do="thatagain"/> <Actions> <Action do="thatagainreally"/> </Actions></sadfasdf>\[/code\]And from there; get only the \[code\]<action/>\[/code\] and format a proper XML document from there and send that over the wire.Is this the best way? What javascript/jquery technique can I use to query just \[code\]<action>\[/code\] tags its descendants?Am I setting myself up for a huge security blunder down the line? I'm taking steps to only send validated XML over the wire and to the server.
 
Back
Top