<commit_before>import * as libxmljs from 'libxmljs';

const xml =  '<?xml version="1.0" encoding="UTF-8"?>' +
           '<root>' +
               '<child foo="bar">' +
                   '<grandchild baz="fizbuzz">grandchild content</grandchild>' +
               '</child>' +
               '<sibling>with content!</sibling>' +
           '</root>';

const xmlDoc = libxmljs.parseXml(xml);

// xpath queries
const gchild = xmlDoc.get('//grandchild')!;

console.log(gchild.text());  // prints "grandchild content"

const children = xmlDoc.root()!.childNodes();
const child = children[0] as libxmljs.Element;

console.log(child.attr('foo')!.value()); // prints "bar"

const parser = new libxmljs.SaxParser();

parser.on('startDocument', () => 0);
parser.on('startElement', () => 0);

const parser2 = new libxmljs.SaxPushParser();

// connect any callbacks here
parser2
  .on('startDocument', () => 0)
  .on('startElement', () => 0);

const xmlChunk = '';

while (xmlChunk) {
  parser2.push(xmlChunk);
}

const doc = new libxmljs.Document();
  ((doc.node('root')
    .node('child').attr({foo: 'bar'})
      .node('grandchild', 'grandchild content').attr({baz: 'fizbuzz'})
    .parent()
  )  as libxmljs.Element).parent()
    .node('sibling', 'with content!');

const {name, externalId, systemId} = doc.getDtd();
<commit_msg>Add a test for Document.get with namespaces<commit_after>import * as libxmljs from 'libxmljs';

const xml =  '<?xml version="1.0" encoding="UTF-8"?>' +
           '<root>' +
               '<child foo="bar">' +
                   '<grandchild baz="fizbuzz">grandchild content</grandchild>' +
               '</child>' +
               '<sibling>with content!</sibling>' +
           '</root>';

const xmlDoc = libxmljs.parseXml(xml);

// xpath queries
const gchild = xmlDoc.get('//grandchild')!;

console.log(gchild.text());  // prints "grandchild content"

const children = xmlDoc.root()!.childNodes();
const child = children[0] as libxmljs.Element;

console.log(child.attr('foo')!.value()); // prints "bar"

const parser = new libxmljs.SaxParser();

parser.on('startDocument', () => 0);
parser.on('startElement', () => 0);

const parser2 = new libxmljs.SaxPushParser();

// connect any callbacks here
parser2
  .on('startDocument', () => 0)
  .on('startElement', () => 0);

const xmlChunk = '';

while (xmlChunk) {
  parser2.push(xmlChunk);
}

const doc = new libxmljs.Document();
  ((doc.node('root')
    .node('child').attr({foo: 'bar'})
      .node('grandchild', 'grandchild content').attr({baz: 'fizbuzz'})
    .parent()
  )  as libxmljs.Element).parent()
    .node('sibling', 'with content!');

const {name, externalId, systemId} = doc.getDtd();

const xmlWithNs =  '<?xml version="1.0" encoding="UTF-8"?>' +
           '<root>' +
               '<child xmlns:a="http://test.com/test" foo="bar">' +
                   '<a:grandchild baz="fizbuzz">grandchild content</a:grandchild>' +
               '</child>' +
               '<sibling>with content!</sibling>' +
           '</root>';

const xmlDocWithNs = libxmljs.parseXml(xmlWithNs);

// xpath queries
const gchildWithNs = xmlDocWithNs.get('//a:grandchild', {"a": "http://test.com/test"})!;
		   
console.log(gchildWithNs.text());  // prints "grandchild content"
{'fraction_non_alphanumeric': 0.19747381392483057, 'fraction_numerical': 0.007701786814540973, 'mean_word_length': 3.2333767926988264, 'pattern_counts': {'":': 1, '<': 30, '<?xml version=': 3, '>': 38, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 41}, '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': '6518608', 'n_tokens_mistral': 1090, 'n_tokens_neox': 1094, 'n_words': 218}