Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to generate/write an ID (alpha-numeric) while adding a new contact in XML file
    text
    copied!<p>Is it possible to generate a alpha-numeric ID during the creation of new contact in the xml file. I used XSLT function <code>&lt;xsl:value-of select="generate-id(.)"/&gt;</code> to generate a unique ID in my xml file in the beginning for serializing so i used the above to generate ID.</p> <p>I can add a new record in xml file using JavaScript DOM in XUL. </p> <pre><code>function create() { var src = "&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\ &lt;CONTACT&gt;\ &lt;Customer-ID&gt;"+document.getElementById("Customer-ID").value+"&lt;/Customer-ID&gt;\ &lt;FirstName&gt;"+document.getElementById("FirstName").value+"&lt;/FirstName&gt;\ &lt;LastName&gt;"+document.getElementById("LastName").value+"&lt;/LastName&gt;\ &lt;email&gt;"+document.getElementById("email").value+"&lt;/email&gt;\ &lt;address&gt;"+document.getElementById("address").value+"&lt;/address&gt;\ &lt;state&gt;"+document.getElementById("state").value+"&lt;/state&gt;\ &lt;country&gt;"+document.getElementById("country").value+"&lt;/country&gt;\ &lt;/CONTACT&gt;"; print(src); var node = srcToNode(src); if (objXMLDoc.childNodes &amp;&amp; objXMLDoc.childNodes.length) { for (var i = 0; i &lt; objXMLDoc.childNodes.length; ++i) { if (objXMLDoc.childNodes.item(i).childNodes &amp;&amp; objXMLDoc.childNodes.item(i).childNodes.length) { var x = objXMLDoc.childNodes.item(i).childNodes.length; var lastNode = objXMLDoc.childNodes.item(i).childNodes.item(x-2); } } objXMLDoc.getElementsByTagName("CONTACT");//objXMLDoc.childNodes.item(0).lastChild; objXMLDoc.appendChild(node); var serializer = new XMLSerializer(); var prettyString = serializer.serializeToString(objXMLDoc); saveFile(prettyString, "C:\\contact.xml"); } } </code></pre> <p>The above code works perfectly to create a new record in my xml file. How can i generate a unique ID during the creation of new contact in my XML file? rather than typing the ID manually in the textbox ?</p> <p>XML File:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;CONTACTS&gt; &lt;CONTACT&gt; &lt;Customer-ID&gt;N65539&lt;/Customer-ID&gt; &lt;FirstName&gt;Ben&lt;/FirstName&gt; &lt;LastName&gt;Foden&lt;/LastName&gt; &lt;email&gt;&lt;/email&gt; &lt;address&gt;&lt;/address&gt; &lt;state&gt;AZ&lt;/state&gt; &lt;country&gt;US&lt;/country&gt; &lt;/CONTACT&gt; &lt;CONTACT&gt; &lt;Customer-ID&gt;N65539&lt;/Customer-ID&gt; &lt;FirstName&gt;Nimal&lt;/FirstName&gt; &lt;LastName&gt;Anup&lt;/LastName&gt; &lt;email&gt;nimal.anup@gmail.com&lt;/email&gt; &lt;address&gt;&lt;/address&gt; &lt;state&gt;TN&lt;/state&gt; &lt;country&gt;IN&lt;/country&gt; &lt;/CONTACT&gt; &lt;CONTACTS&gt; </code></pre>
 

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