Comparing version 0.1.1 to 0.1.2
@@ -153,4 +153,7 @@ (function () { | ||
function XmlDocument(xml) { | ||
xml = xml.trim(); | ||
xml && (xml = xml.toString().trim()); | ||
if (!xml) | ||
throw new Error("No XML to parse!") | ||
var parser = sax.parser(true) // strict | ||
@@ -157,0 +160,0 @@ addParserEvents(parser); |
@@ -9,3 +9,3 @@ { | ||
}, | ||
"version": "0.1.1", | ||
"version": "0.1.2", | ||
"main": "./index", | ||
@@ -21,3 +21,3 @@ "dependencies": { | ||
"type": "git", | ||
"url": "git://github.com/nfarina/xmldoc-js.git" | ||
"url": "git://github.com/nfarina/xmldoc.git" | ||
}, | ||
@@ -24,0 +24,0 @@ "contributors": [ |
@@ -45,14 +45,22 @@ | ||
* `eachChild(func)` - similar to [underscore's][underscore] `each` method, it will call `func(child, index, array)` for each child of the given node. | ||
### eachChild(func) | ||
* `childNamed(name)` - pass it the name of a child node and it will search for and return the first one found, or `undefined`. | ||
Similar to [underscore's][underscore] `each` method, it will call `func(child, index, array)` for each child of the given node. | ||
* `childrenNamed(name)` - like `childNamed` but returns all matching children in an array, or `[]`. | ||
### childNamed(name) | ||
* `childWithAttribute(name,value)` - searches for the first child with the given attribute value. You can omit `value` to just find the first node with the given attribute defined at all. | ||
Pass it the name of a child node and it will search for and return the first one found, or `undefined`. | ||
* `descendantWithPath(path)` - searches for a specific "path" uses dot notation. | ||
### childrenNamed(name) | ||
Example: | ||
Like `childNamed` but returns all matching children in an array, or `[]`. | ||
### childWithAttribute(name,value) | ||
Searches for the first child with the given attribute value. You can omit `value` to just find the first node with the given attribute defined at all. | ||
### descendantWithPath(path) | ||
Searches for a specific "path" uses dot notation. Example: | ||
<book> | ||
@@ -70,5 +78,5 @@ <author> | ||
* `valueWithPath(path)` - just like `descendantWithPath`, but goes deeper and extracts the `val` of the node. | ||
### valueWithPath(path) | ||
Example: | ||
Just like `descendantWithPath`, but goes deeper and extracts the `val` of the node. Example: | ||
@@ -83,4 +91,16 @@ var authorName = bookNode.valueWithPath("author.name"); // return "George R. R. Martin" | ||
* `toString()` - this is just an override of the standard JavaScript method, it will give you the pretty-printed string representation of your XML document or element. Note that this is for debugging only! It will truncate any long node values. | ||
### toString() | ||
This is just an override of the standard JavaScript method, it will give you the pretty-printed string representation of your XML document or element. Note that this is for debugging only! It will truncate any long node values. | ||
var xml = "<author><name>looooooong value</name></author>"; | ||
console.log("My document: \n" + new XmlDocument(xml)) | ||
Prints: | ||
My Document: | ||
<hello> | ||
loooooooo… | ||
</hello> | ||
## Feedback | ||
@@ -87,0 +107,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
14094
195
111