<commit_before><html> 
<head> 
    <script src="../../lib/OpenLayers.js"></script> 
    <script type="text/javascript">

    var text =
        '<?xml version="1.0"?>' + 
        '<ol:root xmlns="http://namespace.default.net" ' +
                 'xmlns:ol="http://namespace.openlayers.org" ' + 
                 'xmlns:ta="http://namespace.testattribute.net">' +
            '<ol:child ta:attribute="value1" ' +
                      'attribute="value2">' +
                'junk1' +
            '<' + '/ol:child>' +
            '<ol:child>junk2<' + '/ol:child>' +
            '<ol:child>junk3<' + '/ol:child>' +
            '<element>junk4<' + '/element>' + 
            '<ol:element>junk5<' + '/ol:element>' + 
        '<' + '/ol:root>';

    function test_Format_XML_constructor(t) { 
        t.plan(5); 
         
        var options = {'foo': 'bar'}; 
        var format = new OpenLayers.Format.XML(options); 
        t.ok(format instanceof OpenLayers.Format.XML, 
             "new OpenLayers.Format.XML returns object" ); 
        t.eq(format.foo, "bar", "constructor sets options correctly"); 
        t.eq(typeof format.read, "function", "format has a read function"); 
        t.eq(typeof format.write, "function", "format has a write function");

        t.ok(!window.ActiveXObject || format.xmldom, "browsers with activeX must have xmldom");
    }

    function test_Format_XML_read(t) {
        
        var format = new OpenLayers.Format.XML();
        t.plan(format.xmldom ? 11 : 10);

        var doc = format.read(text);
        t.eq(doc.nodeType, 9,
             "doc has the correct node type");
        t.eq(doc.nodeName, "#document",
             "doc has the correct node name");
        t.ok(doc.documentElement,
             "ok to access doc.documentElement");
        t.eq(doc.documentElement.nodeName, "ol:root",
             "doc root has the correct node name");
        t.eq(doc.documentElement.childNodes[1].firstChild.nodeValue, "junk2",
             "second child of doc root has correct child node");
        
        // read can also be called on the prototype directly
        doc = OpenLayers.Format.XML.prototype.read(text);
        t.eq(doc.nodeType, 9,
             "doc has the correct node type");
        t.eq(doc.nodeName, "#document",
             "doc has the correct node name");
        t.ok(doc.documentElement,
             "ok to access doc.documentElement");
        t.eq(doc.documentElement.nodeName, "ol:root",
             "doc root has the correct node name");
        t.eq(doc.documentElement.childNodes[1].firstChild.nodeValue, "junk2",
             "second child of doc root has correct child node");
        
        // where appropriate, make sure doc is loaded into xmldom property
        if(format.xmldom) {
            t.eq(format.xmldom.documentElement.childNodes[1].firstChild.nodeValue,
                 "junk2",
                 "second child of doc root has correct child node");
        }
    }

    function test_Format_XML_write(t) {
        t.plan(2);

        var format = new OpenLayers.Format.XML();
        var doc = format.read(text);
        var out = format.write(doc);
        out = out.replace(/[\r\n]/g, '');
        out = out.replace( /<\?.*\?>/, '')
        var expected = text.replace(/<\?.*\?>/, '')
        t.eq(expected, out,
             "correctly writes an XML DOM doc");
        var out = format.write(
          format.getElementsByTagNameNS(doc,
           "http://namespace.openlayers.org","root")[0]);
        t.eq(out, expected,
             "correctly writes an XML DOM node");
    }

    function test_Format_XML_createElementNS(t) {
        t.plan(5);

        var format = new OpenLayers.Format.XML();
        var uri = "http://foo.com";
        var prefix = "foo";
        var localName = "bar";
        var qualifiedName = prefix + ":" + name;
        var node = format.createElementNS(uri, qualifiedName);
        t.eq(node.nodeType, 1,
             "node has correct type");
        t.eq(node.nodeName, qualifiedName,
             "node has correct qualified name");
        t.eq(node.prefix, prefix,
             "node has correct prefix");
        t.eq(node.namespaceURI, uri,
             "node has correct namespace uri");
        <commit_msg>bring back removal of XML prolog.<commit_after><html> 
<head> 
    <script src="../../lib/OpenLayers.js"></script> 
    <script type="text/javascript">

    var text =
        '<?xml version="1.0"?>' + 
        '<ol:root xmlns="http://namespace.default.net" ' +
                 'xmlns:ol="http://namespace.openlayers.org" ' + 
                 'xmlns:ta="http://namespace.testattribute.net">' +
            '<ol:child ta:attribute="value1" ' +
                      'attribute="value2">' +
                'junk1' +
            '<' + '/ol:child>' +
            '<ol:child>junk2<' + '/ol:child>' +
            '<ol:child>junk3<' + '/ol:child>' +
            '<element>junk4<' + '/element>' + 
            '<ol:element>junk5<' + '/ol:element>' + 
        '<' + '/ol:root>';

    function test_Format_XML_constructor(t) { 
        t.plan(5); 
         
        var options = {'foo': 'bar'}; 
        var format = new OpenLayers.Format.XML(options); 
        t.ok(format instanceof OpenLayers.Format.XML, 
             "new OpenLayers.Format.XML returns object" ); 
        t.eq(format.foo, "bar", "constructor sets options correctly"); 
        t.eq(typeof format.read, "function", "format has a read function"); 
        t.eq(typeof format.write, "function", "format has a write function");

        t.ok(!window.ActiveXObject || format.xmldom, "browsers with activeX must have xmldom");
    }

    function test_Format_XML_read(t) {
        
        var format = new OpenLayers.Format.XML();
        t.plan(format.xmldom ? 11 : 10);

        var doc = format.read(text);
        t.eq(doc.nodeType, 9,
             "doc has the correct node type");
        t.eq(doc.nodeName, "#document",
             "doc has the correct node name");
        t.ok(doc.documentElement,
             "ok to access doc.documentElement");
        t.eq(doc.documentElement.nodeName, "ol:root",
             "doc root has the correct node name");
        t.eq(doc.documentElement.childNodes[1].firstChild.nodeValue, "junk2",
             "second child of doc root has correct child node");
        
        // read can also be called on the prototype directly
        doc = OpenLayers.Format.XML.prototype.read(text);
        t.eq(doc.nodeType, 9,
             "doc has the correct node type");
        t.eq(doc.nodeName, "#document",
             "doc has the correct node name");
        t.ok(doc.documentElement,
             "ok to access doc.documentElement");
        t.eq(doc.documentElement.nodeName, "ol:root",
             "doc root has the correct node name");
        t.eq(doc.documentElement.childNodes[1].firstChild.nodeValue, "junk2",
             "second child of doc root has correct child node");
        
        // where appropriate, make sure doc is loaded into xmldom property
        if(format.xmldom) {
            t.eq(format.xmldom.documentElement.childNodes[1].firstChild.nodeValue,
                 "junk2",
                 "second child of doc root has correct child node");
        }
    }

    function test_Format_XML_write(t) {
        t.plan(2);

        var format = new OpenLayers.Format.XML();
        var doc = format.read(text);
        var out = format.write(doc);
        out = out.replace(/[\r\n]/g, '');
        out = out.replace( /<\?.*\?>/, '')
        var expected = text.replace(/<\?.*\?>/, '')
        t.eq(expected, out,
             "correctly writes an XML DOM doc");
        var out = format.write(
          format.getElementsByTagNameNS(doc,
           "http://namespace.openlayers.org","root")[0]);
        out = out.replace(/[\r\n]/g, '');
        out = out.replace( /<\?.*\?>/, '')
        t.eq(out, expected,
             "correctly writes an XML DOM node");
    }

    function test_Format_XML_createElementNS(t) {
        t.plan(5);

        var format = new OpenLayers.Format.XML();
        var uri = "http://foo.com";
        var prefix = "foo";
        var localName = "bar";
        var qualifiedName = prefix + ":" + name;
        var node = format.createElementNS(uri, qualifiedName);
        t.eq(node.nodeType, 1,
             "node has correct type");
        t.eq(node.nodeName, qualifiedName,
             "node has correct qualified name");
        t.eq(node.prefix, prefix,
             "node has correct prefix");
        t.eq(node.namespaceURI, uri,
             "node has correct namespace uri");
        
{'fraction_non_alphanumeric': 0.14509576320371445, 'fraction_numerical': 0.006035983749274521, 'mean_word_length': 1.9476565172767704, 'pattern_counts': {'":': 2, '<': 44, '<?xml version=': 2, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 20}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3486156', 'n_tokens_mistral': 2607, 'n_tokens_neox': 2547, 'n_words': 597}