xml-stream
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -102,3 +102,3 @@ var events = require('events') | ||
if (!--self._bufferLevel && self._emitData) { | ||
emitElement.call(self, element, element.$name, true); | ||
emitElement.call(self, element, self._name, true); | ||
} | ||
@@ -292,3 +292,3 @@ }); | ||
if (self._bufferLevel === 0 && self._emitData) { | ||
emitStart.call(self, element.$name, element.$); | ||
emitStart.call(self, name, element.$); | ||
} | ||
@@ -310,2 +310,3 @@ }); | ||
var name = element.$name; | ||
self._name = name; | ||
delete element.$; | ||
@@ -321,7 +322,6 @@ delete element.$text; | ||
} | ||
if (attr !== null) { | ||
if (!isEmpty(attr)) { | ||
element.$ = attr; | ||
} | ||
} | ||
element.$name = name; | ||
curr.context[name] = val; | ||
@@ -350,3 +350,39 @@ if (curr.collect) { | ||
} | ||
curr.fullText += curr.element.$text; | ||
var trimmed = curr.element.$text.trim(); | ||
var spaced = curr.element.$text.substr(0, 1); | ||
spaced = (spaced !== '') && (spaced.trim() === ''); | ||
var after = curr.element.$text.substr(-1, 1); | ||
after = (after !== '') && (after.trim() === ''); | ||
switch (curr.space) { | ||
// No words yet (pass through spaces). | ||
case 0: | ||
if (trimmed !== '') { | ||
curr.space = after ? 2 : 1; | ||
} | ||
break; | ||
// Immediately after text or entity. | ||
case 1: | ||
if (trimmed === '') { | ||
curr.space = 2; | ||
} else { | ||
if (spaced) { | ||
curr.fullText += ' '; | ||
} | ||
if (after) { | ||
curr.space = 2; | ||
} | ||
} | ||
break; | ||
// Some words were emitted, pass through spaces again. | ||
// Emit spaces only when a word is encountered afterwards. | ||
case 2: | ||
if (trimmed !== '') { | ||
curr.fullText += ' '; | ||
curr.space = 1; | ||
} | ||
break; | ||
} | ||
curr.fullText += trimmed; | ||
}); | ||
@@ -353,0 +389,0 @@ |
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "0.3.1", | ||
"version": "0.3.2", | ||
"author": "AssistUnion <info@assistunion.com>", | ||
@@ -12,0 +12,0 @@ "maintainers": [ |
@@ -39,1 +39,35 @@ # XmlStream | ||
Take a look at the examples for more information. | ||
## Element Node | ||
Each of the four node events has a callback with one argument. When parsing, | ||
this argument is set to the current matched node. Having a chunk of XML like | ||
this: | ||
```xml | ||
<item id="123" type="common"> | ||
<title>Item Title</title> | ||
<description>Description of this item.</description> | ||
(text) | ||
</item> | ||
``` | ||
The structure of the **item** element node would be: | ||
```javascript | ||
{ | ||
title: 'Item Title', | ||
description: 'Description of this item.', | ||
'$': { | ||
'id': '123', | ||
'type': 'common' | ||
}, | ||
'$name': 'item', | ||
'$text': '(text)' | ||
} | ||
``` | ||
Naturally, element text and child elements wouldn't be known until discovered | ||
in the stream, so the structure may differ across events. The complete | ||
structure as displayed should be available on **updateElement**. The **$name** | ||
is not available on **endElement**. |
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
19375
520
73