Xml

http://coderstoolbox.net/string/

https://www.eclipse.org/webtools/community/tutorials/XMLValidation/XMLValidationTutorial.html
https://stackoverflow.com/questions/7489510/disable-xml-validation-in-eclipse
https://docs.oracle.com/javase/tutorial/jaxp/dom/validating.html
https://www.ibm.com/developerworks/xml/library/x-javaxmlvalidapi/
https://help.eclipse.org/neon/index.jsp?topic=%2Forg.eclipse.wst.xmleditor.doc.user%2Ftopics%2Ftwxvalid.html
https://www.oxygenxml.com/xml_editor/eclipse_plugin.html
https://www.programcreek.com/java-api-examples/javax.xml.validation.Validator
http://www.edankert.com/validate.html
http://www.javased.com/?api=javax.xml.validation.Validator
https://docs.oracle.com/javase/7/docs/api/javax/xml/validation/package-summary.html

http://www.javaworld.com/article/2077668/soa/accelerate-wss-applications-with-vtd-xml.html
http://www.javaworld.com/article/2071797/soa/cut--paste--split--and-assemble-xml-documents-with-vtd-xml.html
http://www.javaworld.com/article/2077736/open-source-tools/xml-merging-made-easy.html
http://www.javaworld.com/article/2077738/open-source-tools/turbolinux-to-help-translate-open-xml-for-asia.html

Working with XML using Java

What did I do to handle special characters?

I needed to remove all control characters / unicode characters that make our XML files invalid. On one hand, we should remove these invalid characters when we do validation. On the other hand, if these characters somehow made their way into our database, we should wrap them in a CDATA or encode them somehow so that we produce valid XML. We did not have proper way to encode the data coming from the database.

function removeControlCharactersFromText(text) {
    // http://en.wikipedia.org/wiki/List_of_Unicode_characters
    // http://ss64.com/ascii.html
    // http://www.ssec.wisc.edu/~tomw/java/unicode.html#x0000
    var original = text;
    /*
    text = text.replace(/\u00BF/g,''); // inverted question mark
    text = text.replace(/\u00E2/gi,''); // The â
    text = text.replace(/\u00BD/g,'1/2'); // The ½
    text = text.replace(/\u00BE/g,'3/4'); // The ¾
    */

    // But isInvalidString function defined in /javascript/validateForm.js is stricter than the above code
    text = text.replace(/[^\u000D\u00B7\u0020-\u007E\u00A2-\u00A4]/g,'');
    return text;
}
function removeControlCharacters(node) {
    var nodeName = node.nodeName.toLowerCase();
    if (nodeName == "input") {
        var isTextInputNode = false;
        if ((node.hasAttribute) && (node.getAttribute)) {
            if (node.hasAttribute('type')) {
                var nodeType = node.getAttribute('type').toLowerCase();
                if ((nodeType == 'text') || (nodeType == 'hidden')) {
                    // Ideally if the node is hidden, we should not have to check if it contains control characters
                    // just in case the code create these hidden fields, or set the values for these hidden fields
                    // via an onblur event handler
                    isTextInputNode = true;
                }
            } else {
                // If an input element does have the 'type' attribute, the browser treat it as an input box
                isTextInputNode = true;
            }
        } else {
            var nodeType = node.type;
            if ((nodeType == 'text') || (nodeType == 'hidden')) {
                isTextInputNode = true;
            }
        }
        if (isTextInputNode) {
            node.value = removeControlCharactersFromText(node.value);
        }
    } else if (nodeName == "textarea") {
        node.value = removeControlCharactersFromText(node.value);
    }
}

With EXTJS, we can use the stripCharsRe config option, and the regular expression should be:

/* RegEx for removing potential 'CONTROL CHARACTERS (C0, C1)' in input fields to ensure XML documents are not corrupted.*/ 
var stripInvalidXmlCharacters = /[^\u0009\u000A\u000D\u0020-\uD7FF\uE000-\uFFFD\u1000-\u10FFFF]|[&><”’]/g;

The characters inside the second character class: ampersand, greater than sign, less than sign, double quote, and single quote

var swapCodes = new Array(8211, 8212, 8216, 8217, 8220, 8221, 8226, 8230); // dec codes from char at
var swapStrings = new Array("--", "--", "'", "'", "\"", "\"", "*", "...");
function cleanWordClipboard(input) {
    // debug for new codes
    // for (i = 0; i < input.length; i++) alert("'" + input.charAt(i) + "': " + input.charCodeAt(i));
    var output = input;
    for (i = 0; i < swapCodes.length; i++) {
        var swapper = new RegExp("\\u" + swapCodes[i].toString(16), "g"); // hex codes
        output = output.replace(swapper, swapStrings[i]);
    }
    return output;
} 
function stripCharsOnPaste(c, e) {
    var keyCode = e.getKey();
    if ((keyCode == 86) && (e.ctrlKey)) {
        setTimeout(function(){
            var text = textTrim(c.getValue());
            var result = cleanWordClipboard(text);
            c.setValue(result);
        }, 10)
    }
}
jQuery(document).ready(function(){
    jQuery('body').keyup(function(e) {
        var keyCode = e.which;
        if ((keyCode == 86) && (e.ctrlKey)) {
            debugger;
            var domEl = e.target;
            var domId = domEl.getAttribute('id');
            var c = Ext.getCmp(domId);  // We are assuming that the DOM ID for the element is also the ID for the component
            var needBrute = false;
            if (typeof(c) != 'undefined') {
                if (c.getEl().id != domId) {
                    needBrute = true;
                } 
            } else {
                needBrute = true;
            }
            if (needBrute) {
                var mx = Ext.ComponentMgr.all;
                mx.each(function(){
                    if (this.getEl().id == domId) {
                        c = this;
                        return false; // Stop iterating
                    }
                })
            }
            if (typeof(c) != 'undefined') {
                setTimeout(function(){
                    var text = textTrim(c.getValue());
                    var result = cleanWordClipboard(text);
                    c.setValue(result);
                }, 10);
            } else {
                setTimeout(function(){
                    var jc = jQuery(domEl);
                    var text = jc.val();
                    var result = cleanWordClipboard(text);
                    jc.val(result);
                }, 10);
            }
        }
    });
});

What are some JavaScript-based XML parser?

How can we work with XML using JavaScript? What are some methods and examples for working with XML using JavaScript?

var k = getActiveObj(document.all("srcXml").innerHTML);
k2.childNodes[0].data;
k2.childNodes[0].nodeValue;
getElementsByTagName("title")[0];
var k2 = k.selectSingleNode("//tasksTblRow[@id=226815553]/inboxData/col[@id='_FUPSTATUS']");
firstChild
nextSibling
nodeName
x.nodeValue
x.nodeValue = "..."
nodeType
parentNode

xmlDoc.createElement("edition")
x=xmlDoc.getElementsByTagName("book")[0];
x.appendChild(newel); 

xmlDoc.xml // convert the xmlDoc to string

window.opener.document.getElementById('row'+tempinboxID+'_FUPSTATUS').innerHTML = 'Complete';
var srcXmlObj = getActiveObj(window.opener.document.all("srcXml").innerHTML);
srcXmlObj.selectSingleNode("//tasksTblRow[@id=" + tempinboxID + "]/inboxData/col[@id='_FUPSTATUS']").childNodes[0].nodeValue = 'Complete';
window.opener.document.all("srcXml").innerHTML = srcXmlObj.xml;

Parsing XML file for Firefox:

https://developer.mozilla.org/en-US/docs/Web/API/document.evaluate
https://developer.mozilla.org/en-US/docs/Using_XPath
https://developer.mozilla.org/en-US/docs/Introduction_to_using_XPath_in_JavaScript#Implementing_a_Default_Namespace_Resolver
https://developer.mozilla.org/en-US/docs/Introduction_to_using_XPath_in_JavaScript#Implementing_a_User_Defined_Namespace_Resolver

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License