Permalink
Browse files

Rename libxml.parse(Xml|Html)String to parse(Xml|Html)

In preparation for adding support for buffers.  The old names are
still supported.
  • Loading branch information...
1 parent f4707b5 commit 375b51cbbee1e63a67e6ccb484711f664e8d8bff @dpw dpw committed Jul 7, 2012
View
@@ -13,7 +13,7 @@ var xml = '<?xml version="1.0" encoding="UTF-8"?>' +
'<sibling>with content!</sibling>' +
'</root>';
-var xmlDoc = libxmljs.parseXmlString(xml);
+var xmlDoc = libxmljs.parseXml(xml);
// xpath queries
var gchild = xmlDoc.get('//grandchild');
View
@@ -11,7 +11,7 @@ LibXML bindings for [node.js](http://nodejs.org/)
'<sibling>with content!</sibling>' +
'</root>';
- var xmlDoc = libxmljs.parseXmlString(xml);
+ var xmlDoc = libxmljs.parseXml(xml);
// xpath queries
var gchild = xmlDoc.get('//grandchild');
@@ -81,7 +81,7 @@ By file:
By String:
- var doc = libxml.parseXmlString([xmlString]);
+ var doc = libxml.parseXml([xmlString]);
#### SAX Parsing
View
@@ -6,7 +6,7 @@ the document as a set of javascript objects is returned
### Methods
-#### libxmljs.parseXmlString(string)
+#### libxmljs.parseXml(string)
>Parse an in-memory XML string
@@ -26,7 +26,7 @@ the document as a set of javascript objects is returned
>**returns** an XmlDocument object
-#### libxmljs.parseHtmlString(string)
+#### libxmljs.parseHtml(string)
>Parse an in-memory HTML string
View
@@ -7,14 +7,10 @@ var bindings = require('./lib/bindings');
var Document = require('./lib/document');
/// parse an xml string and return a Document
-module.exports.parseXmlString = function(string) {
- return Document.fromXmlString(string);
-}
+module.exports.parseXml = Document.fromXml;
/// parse an html string and return a Document
-module.exports.parseHtmlString = function(string) {
- return Document.fromHtmlString(string);
-}
+module.exports.parseHtml = Document.fromHtml;
// constants
module.exports.version = bindings.version;
@@ -26,6 +22,12 @@ module.exports.libxml_debug_enabled = bindings.libxml_debug_enabled;
module.exports.Document = Document;
module.exports.Element = require('./lib/element');
+// Compatibility synonyms
+Document.fromXmlString = Document.fromXml;
+Document.fromHtmlString = Document.fromHtmlString;
+module.exports.parseXmlString = module.exports.parseXml;
+module.exports.parseHtmlString = module.exports.parseHtml;
+
var sax_parser = require('./lib/sax_parser');
module.exports.SaxParser = sax_parser.SaxParser;
module.exports.SaxPushParser = sax_parser.SaxPushParser;
View
@@ -83,14 +83,14 @@ module.exports = Document;
/// parse a string into a html document
/// @param string html string to parse
/// @return a Document
-module.exports.fromHtmlString = function(string) {
- return bindings.fromHtmlString(string);
+module.exports.fromHtml = function(string) {
+ return bindings.fromHtml(string);
}
/// parse a string into a xml document
/// @param string xml string to parse
/// @return a Document
-module.exports.fromXmlString = function(string) {
- return bindings.fromXmlString(string);
+module.exports.fromXml = function(string) {
+ return bindings.fromXml(string);
}
View
@@ -130,7 +130,7 @@ XmlDocument::New(xmlDoc* doc)
}
v8::Handle<v8::Value>
-XmlDocument::FromHtmlString(const v8::Arguments& args)
+XmlDocument::FromHtml(const v8::Arguments& args)
{
v8::HandleScope scope;
@@ -161,7 +161,7 @@ XmlDocument::FromHtmlString(const v8::Arguments& args)
}
v8::Handle<v8::Value>
-XmlDocument::FromXmlString(const v8::Arguments& args)
+XmlDocument::FromXml(const v8::Arguments& args)
{
v8::HandleScope scope;
@@ -290,8 +290,8 @@ XmlDocument::Initialize(v8::Handle<v8::Object> target)
"_validate",
XmlDocument::Validate);
- NODE_SET_METHOD(target, "fromXmlString", XmlDocument::FromXmlString);
- NODE_SET_METHOD(target, "fromHtmlString", XmlDocument::FromHtmlString);
+ NODE_SET_METHOD(target, "fromXml", XmlDocument::FromXml);
+ NODE_SET_METHOD(target, "fromHtml", XmlDocument::FromHtml);
// used to create new document handles
target->Set(v8::String::NewSymbol("Document"), t->GetFunction());
View
@@ -40,8 +40,8 @@ class XmlDocument : public node::ObjectWrap {
explicit XmlDocument(xmlDoc* doc);
static v8::Handle<v8::Value> New(const v8::Arguments& args);
- static v8::Handle<v8::Value> FromHtmlString(const v8::Arguments& args);
- static v8::Handle<v8::Value> FromXmlString(const v8::Arguments& args);
+ static v8::Handle<v8::Value> FromHtml(const v8::Arguments& args);
+ static v8::Handle<v8::Value> FromXml(const v8::Arguments& args);
// document handle methods
static v8::Handle<v8::Value> Root(const v8::Arguments& args);
View
@@ -4,7 +4,7 @@ var body = "<?xml version='1.0' encoding='UTF-8'?>\n" +
"<root><node attr-one-key='attr-one-value' attr-two-key='attr-two-value' attr-three-key='attr-three-value' /></root>";
module.exports.new = function(assert) {
- var doc = libxml.parseXmlString(body);
+ var doc = libxml.parseXml(body);
var node = doc.get('node');
// add new attribute to the node
@@ -14,7 +14,7 @@ module.exports.new = function(assert) {
};
module.exports.create_with_namespace = function(assert) {
- var doc = new libxml.parseXmlString(
+ var doc = new libxml.parseXml(
"<?xml version='1.0' encoding='UTF-8'?>\n"+
"<root><node attr-one-key='attr-one-value' attr-two-key='attr-two-value' attr-three-key='attr-three-value' /></root>"
);
@@ -29,7 +29,7 @@ module.exports.create_with_namespace = function(assert) {
};
module.exports.getters = function(assert) {
- var doc = libxml.parseXmlString(body);
+ var doc = libxml.parseXml(body);
var node = doc.get('node');
assert.equal('attr-one-key', node.attr('attr-one-key').name());
@@ -45,7 +45,7 @@ module.exports.getters = function(assert) {
};
module.exports.setters = function(assert) {
- var doc = libxml.parseXmlString(body);
+ var doc = libxml.parseXml(body);
var node = doc.get('node');
node.attr('attr-one-key').value('new-value');
@@ -55,7 +55,7 @@ module.exports.setters = function(assert) {
/*
module.exports.namespace = function(assert) {
- var doc = libxml.parseXmlString(body);
+ var doc = libxml.parseXml(body);
var node = doc.get('node');
var ns = new libxml.Namespace(node, 'ns-prefix', 'ns-uri');
@@ -68,7 +68,7 @@ module.exports.namespace = function(assert) {
*/
module.exports.remove = function(assert) {
- var doc = libxml.parseXmlString(body);
+ var doc = libxml.parseXml(body);
var node = doc.get('node');
var attr = node.attr('attr-one-key');
View
@@ -100,8 +100,8 @@ module.exports.add_child_nodes = function(assert) {
'<root><child to="wongfoo"></child><sibling>with content!</sibling></root>',
].join("\n");
- var doc1 = libxml.parseXmlString(doc1_string);
- var doc2 = libxml.parseXmlString(doc2_string);
+ var doc1 = libxml.parseXml(doc1_string);
+ var doc2 = libxml.parseXml(doc2_string);
doc2.child(0).addChild(doc1.child(0).child(0));
assert.equal(doc1.toString(), doc2.toString());
assert.done();
@@ -120,7 +120,7 @@ module.exports.add_cdata_nodes = function(assert) {
'' /* Why?!? */
].join("\n");
- var doc1 = libxml.parseXmlString(doc1_string);
+ var doc1 = libxml.parseXml(doc1_string);
doc1.child(0).cdata('<p>Bacon</p>');
assert.equal(doc1.toString(), expected_string);
assert.done();
@@ -140,8 +140,8 @@ module.exports.cloned_node = function(assert) {
''
].join("\n");
- var doc1 = libxml.parseXmlString(doc1_string);
- var doc2 = libxml.parseXmlString(doc2_string);
+ var doc1 = libxml.parseXml(doc1_string);
+ var doc2 = libxml.parseXml(doc2_string);
var gchild = doc1.child(0).child(0); //the element to operate on
@@ -163,9 +163,9 @@ module.exports.validate = function(assert) {
var xml_valid = '<?xml version="1.0"?><comment>A comment</comment>';
var xml_invalid = '<?xml version="1.0"?><commentt>A comment</commentt>';
- var xsdDoc = libxml.parseXmlString(xsd);
- var xmlDocValid = libxml.parseXmlString(xml_valid);
- var xmlDocInvalid = libxml.parseXmlString(xml_invalid);
+ var xsdDoc = libxml.parseXml(xsd);
+ var xmlDocValid = libxml.parseXml(xml_valid);
+ var xmlDocInvalid = libxml.parseXml(xml_invalid);
assert.equal(xmlDocValid.validate(xsdDoc), true);
assert.equal(xmlDocInvalid.validate(xsdDoc), false);
View
@@ -15,13 +15,18 @@ module.exports.parse = function(assert) {
var filename = __dirname + '/fixtures/parser.html';
var str = fs.readFileSync(filename, 'utf8');
- var doc = libxml.parseHtmlString(str);
+ var doc = libxml.parseHtml(str);
assert.equal('html', doc.root().name());
assert.equal('Test HTML document', doc.get('head/title').text());
assert.equal('HTML content!', doc.get('body/span').text());
assert.done();
};
+module.exports.parse_synonym = function(assert) {
+ assert.strictEqual(libxml.parseHtml, libxml.parseHtmlString);
+ assert.done();
+}
+
module.exports.recoverable_parse = function(assert) {
var recoverableFile = __dirname +'/fixtures/warnings/amp.html';
var str = fs.readFileSync(recoverableFile, 'utf8');
@@ -52,7 +57,7 @@ module.exports.recoverable_parse = function(assert) {
column: 4 })
];
- var doc = libxml.parseHtmlString(str);
+ var doc = libxml.parseHtml(str);
assert.equal(4, doc.errors.length);
for(var i = 0; i < recoverableErrors.length; i++) {
assert.equal(recoverableErrors[i].domain, doc.errors[i].domain);
View
@@ -45,20 +45,20 @@ module.exports.with_prefix = function(assert) {
};
module.exports.from_parsing = function(assert) {
- var doc = libxml.parseXmlString('<?xml version="1.0" encoding="UTF-8"?>' +
+ var doc = libxml.parseXml('<?xml version="1.0" encoding="UTF-8"?>' +
'<name1 xmlns="http://my-namespace.com"/>');
var elem = doc.root();
assert.ok(elem.namespace());
assert.equal(null, elem.namespace().prefix());
assert.equal('http://my-namespace.com', elem.namespace().href());
// no prefix from parsing
- var doc = libxml.parseXmlString('<?xml version="1.0" encoding="UTF-8"?>' +
+ var doc = libxml.parseXml('<?xml version="1.0" encoding="UTF-8"?>' +
'<name1 xmlns:pref="http://my-namespace.com"/>');
var elem = doc.root();
assert.ok(!elem.namespace());
- var doc = libxml.parseXmlString('<?xml version="1.0" encoding="UTF-8"?>' +
+ var doc = libxml.parseXml('<?xml version="1.0" encoding="UTF-8"?>' +
'<pref:name1 xmlns:pref="http://my-namespace.com"/>');
var elem = doc.root();
assert.ok(elem.namespace());
View
@@ -17,7 +17,7 @@ module.exports.gc = function(assert) {
};
module.exports.references = function(assert) {
- var nodes = libxml.parseXmlString('<root> <child> <grandchildren/> </child> <child2/></root>').childNodes();
+ var nodes = libxml.parseXml('<root> <child> <grandchildren/> </child> <child2/></root>').childNodes();
gc();
View
@@ -30,7 +30,7 @@ module.exports.get_attr = function(assert) {
assert.equal('val', doc.get('child').get('@attr').value());
// check again after re-parsign the doc
- doc = libxml.parseXmlString(doc.toString())
+ doc = libxml.parseXml(doc.toString())
assert.equal('val', doc.get('//@attr').value());
assert.equal('val', doc.get('child').get('@attr').value());
assert.equal(doc.get('child'), doc.get('//@attr').node());
View
@@ -1,14 +1,14 @@
var libxml = require('../index');
module.exports.text = function(assert) {
- var doc = libxml.parseXmlString('<?xml version="1.0"?><root>child</root>');
+ var doc = libxml.parseXml('<?xml version="1.0"?><root>child</root>');
assert.equal('text', doc.child(0).type());
assert.equal('text', doc.child(0).name());
assert.done();
};
module.exports.comment = function(assert) {
- var doc = libxml.parseXmlString('<?xml version="1.0"?>' +
+ var doc = libxml.parseXml('<?xml version="1.0"?>' +
'<root><!-- comment --></root>');
assert.equal('comment', doc.child(0).type());
assert.equal('comment', doc.child(0).name());
@@ -17,7 +17,7 @@ module.exports.comment = function(assert) {
module.exports.cdata = function(assert) {
- var doc = libxml.parseXmlString('<?xml version="1.0"?>' +
+ var doc = libxml.parseXml('<?xml version="1.0"?>' +
'<root><![CDATA[cdata text]]></root>');
assert.equal('cdata', doc.child(0).type());
View
@@ -47,7 +47,7 @@ module.exports.siblings = function(assert) {
};
module.exports.parsed = function(assert) {
- var doc = libxml.parseXmlString(
+ var doc = libxml.parseXml(
'<?xml version="1.0"?>' +
'<root><child><grandchild /></child><sibling/></root>');
assert.equal(doc, doc.child(0).doc());
@@ -67,7 +67,7 @@ module.exports.parsed = function(assert) {
};
module.exports.parsed_children = function(assert) {
- var doc = libxml.parseXmlString(
+ var doc = libxml.parseXml(
'<?xml version="1.0"?>' +
'<root><prevSibling /><child /><nextSibling /></root>');
var children = ['prevSibling', 'child', 'nextSibling'];
View
@@ -6,7 +6,7 @@ module.exports.parse = function(assert) {
var filename = __dirname + '/fixtures/parser.xml';
var str = fs.readFileSync(filename, 'utf8');
- var doc = libxml.parseXmlString(str);
+ var doc = libxml.parseXml(str);
assert.equal('1.0', doc.version());
assert.equal('UTF-8', doc.encoding());
assert.equal('root', doc.root().name());
@@ -19,11 +19,16 @@ module.exports.parse = function(assert) {
assert.done();
};
+module.exports.parse_synonym = function(assert) {
+ assert.strictEqual(libxml.parseXml, libxml.parseXmlString);
+ assert.done();
+}
+
module.exports.recoverable_parse = function(assert) {
var filename = __dirname + '/fixtures/warnings/ent9.xml';
var str = fs.readFileSync(filename, 'utf8');
- var doc = libxml.parseXmlString(str);
+ var doc = libxml.parseXml(str);
assert.equal(1, doc.errors.length);
var err = doc.errors.shift();
@@ -43,7 +48,7 @@ module.exports.fatal_error = function(assert) {
var err = null;
try {
- libxml.parseXmlString(str);
+ libxml.parseXml(str);
} catch(e) { err = e; }
var errorControl = {

0 comments on commit 375b51c

Please sign in to comment.