Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To store an arbitrary string in XML, use the native XML capabilities of the browser. It will be a hell of a lot simpler that way, plus you will never have to think about the edge cases again (for example attribute values that contain quotes or pointy brackets). </p> <p>A tip to think of when working with XML: <strong>Do never ever ever build XML from strings by concatenation if there is any way to avoid it</strong>. You <em>will</em> get yourself into trouble that way. There are APIs to handle XML, use them.</p> <p>Going from your code, I would suggest the following:</p> <pre><code>$(function() { $("#addbutton").click(function() { var eventXml = XmlCreate("&lt;event/&gt;"); var $event = $(eventXml); $event.attr("title", $("#titlefield").val()); $event.attr("start", [$("#bmonth").val(), $("#bday").val(), $("#byear").val()].join(" ")); if (parseInt($("#eyear").val()) &gt; 0) { $event.attr("end", [$("#emonth").val(), $("#eday").val(), $("#eyear").val()].join(" ")); $event.attr("isDuration", "true"); } else { $event.attr("isDuration", "false"); } $event.text( tinyMCE.activeEditor.getContent() ); $("#outputtext").val( XmlSerialize(eventXml) ); }); }); // helper function to create an XML DOM Document function XmlCreate(xmlString) { var x; if (typeof DOMParser === "function") { var p = new DOMParser(); x = p.parseFromString(xmlString,"text/xml"); } else { x = new ActiveXObject("Microsoft.XMLDOM"); x.async = false; x.loadXML(xmlString); } return x.documentElement; } // helper function to turn an XML DOM Document into a string function XmlSerialize(xml) { var s; if (typeof XMLSerializer === "function") { var x = new XMLSerializer(); s = x.serializeToString(xml); } else { s = xml.xml; } return s } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload