Git Product home page Git Product logo

libxmljs's Introduction

libxmljs

npm version Downloads monthly Downloads total Test & Upload

npm install libxmljs

NodeJS bindings for libxml2 written in Typescript

Documentation

https://libxmljs.github.io/libxmljs/

Examples

For more examples, check out the test suite.

import libxmljs from "libxmljs";

libxmljs
    .parseXmlAsync(
        `
        <?xml version="1.0" encoding="UTF-8"?>
        <root>
            <child foo="bar">
            <grandchild baz="fizbuzz">grandchild content</grandchild>
            </child>
            <sibling>with content!</sibling>
        </root>
        `
    )
    .then((xmlDoc) => {
        const gchild = xmlDoc.find("//grandchild")[0];

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

        const child = xmlDoc.root()?.child(0);

        console.log(child?.getAttribute("foo")?.value()); // prints "bar"
    });

Package Scripts

npm run init-submodules

Clones libxml2 source code to vendor/libxml2

npm run configure

Generate new cmake config headers with cmake in vendor/libxml2.config. Used when updating to a new libxml2 version.

npm run build

Build the C++ source code using node-gyp

npm run swig

Generate a new src/libxml2.cc and swig.xml file by processing the native code using SWIG. Used when making changes to native code or any of the SWIG interface files (src/*.i)

npm run tsgenerate

Generates typescript definitons for native bindings exports. Used when changes are made to native exports. Auto-generates constants.ts, functions.ts, types.ts, and variables.ts within lib/bindings/

npm run tsc

Compiles Typescript within lib/ and outputs it to dist/ Use npm run dev to put Typescript compiler into watch mode.

npm run test

Runs all tests in test/ using nodeunit. Use npm run test -- -t TEST_NAME to run a specific test.

npm run docs

Generates docs/ using Typedoc

libxmljs's People

Contributors

alfyboza avatar azuisleet avatar dachev avatar defunctzombie avatar dependabot[bot] avatar dpw avatar gagern avatar greut avatar hildjj avatar isaacs avatar jdesboeufs avatar jhs67 avatar jmandel avatar joshdata avatar kkoopa avatar mgcrea avatar mureinik avatar ncb000gt avatar pavelkestefran avatar pdehaan avatar polotek avatar rchipka avatar rprinz08 avatar sprsquish avatar teleological avatar thomas-riccardi avatar tootallnate avatar tuananh avatar vgrichina avatar winbergoscar0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

libxmljs's Issues

Unable to compile the latest code in Mac OSX

I tried to compile the latest code in Mac OSx and got the following error

src/xml_node.cc: In member function 'v8::Handlev8::Value libxmljs::XmlNode::to_string()':
src/xml_node.cc:222: error: 'xmlSaveToBuffer' was not declared in this scope
scons: *** [src/xml_node.os] Error 1
scons: building terminated because of errors.

libxmljs fails to install via NPM on Mac OS X 10.6.7

Hello, I was trying to install libxmljs with the following command on Mac OS X 10.6.7, with NPM 0.3.15 and Node 0.4.2:

$ sudo npm install libxmljs

But I got the following output:

npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info preinstall [email protected]
make: scons: No such file or directory
make: *** [node] Error 1
npm info [email protected] Failed to exec preinstall script
npm ERR! install failed Error: [email protected] preinstall: `make node`
npm ERR! install failed `sh "-c" "make node"` failed with 2
npm ERR! install failed     at ChildProcess.<anonymous> (/usr/local/lib/node/.npm/npm/0.3.15/package/lib/utils/exec.js:49:20)
npm ERR! install failed     at ChildProcess.emit (events.js:45:17)
npm ERR! install failed     at ChildProcess.onexit (child_process.js:171:12)
npm info install failed rollback
npm info uninstall [ '[email protected]' ]
npm info preuninstall [email protected]
make: scons: No such file or directory
make: *** [clean] Error 1
npm ERR! [email protected] Error: `sh "-c" "make clean"` failed with 2
npm ERR! [email protected]     at ChildProcess.<anonymous> (/usr/local/lib/node/.npm/npm/0.3.15/package/lib/utils/exec.js:49:20)
npm ERR! [email protected]     at ChildProcess.emit (events.js:45:17)
npm ERR! [email protected]     at ChildProcess.onexit (child_process.js:171:12)
npm ERR! [email protected] failed, but continuing anyway
npm info uninstall [email protected]
npm info auto-deactive not symlink
npm info postuninstall [email protected]
npm info uninstall [email protected] complete
npm info install failed rolled back
npm ERR! Error: [email protected] preinstall: `make node`
npm ERR! `sh "-c" "make node"` failed with 2
npm ERR!     at ChildProcess.<anonymous> (/usr/local/lib/node/.npm/npm/0.3.15/package/lib/utils/exec.js:49:20)
npm ERR!     at ChildProcess.emit (events.js:45:17)
npm ERR!     at ChildProcess.onexit (child_process.js:171:12)
npm ERR! 
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is most likely a problem with the libxmljs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     make node
npm ERR! You can get their info via:
npm ERR!     npm owner ls libxmljs
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 10.7.0
npm ERR! argv { remain: [ 'libxmljs' ],
npm ERR! argv   cooked: [ 'install', 'libxmljs' ],
npm ERR! argv   original: [ 'install', 'libxmljs' ] }
npm not ok

As NPM said, the command make node failed on my system. (Which is kind of strange IMO... the problem is with NPM, perhaps?)

Thanks.

Segfault after moving node between documents

I've got this code segfaulting after some time (1-3 seconds) since executing: http://pastebin.com/60B1iVnJ

Console log:

Spark server(27878) listening on http://*:3000 in development mode
93.158.159.73 - - [Wed, 22 Sep 2010 22:05:46 GMT] "GET /?text=123 HTTP/1.1" 200 - "" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; ru-ru) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5"
93.158.159.73 - - [Wed, 22 Sep 2010 22:05:46 GMT] "GET /favicon.ico HTTP/1.1" 404 - "http://arikon.dev.tools.yandex-team.ru:3000/?text=123" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_4; ru-ru) AppleWebKit/533.18.1 (KHTML, like Gecko) Version/5.0.2 Safari/533.18.5"
Memory tag error occurs :0xb0adcd 
 bye
xmlMemFree(B0ADF5) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0xb0adc7 
 bye
xmlMemFree(B0ADEF) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0xb0add1 
 bye
xmlMemFree(B0ADF9) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0xb0adbf 
 bye
xmlMemFree(B0ADE7) error
xmlMallocBreakpoint reached on block 0
Segmentation fault

issue with strings

I'm trying the following in node.js

http://gist.github.com/396917

what i'm seeing is the string type is always raising this exception on parser.push
Bad Argument: parseString requires a string

The line is
LIBXMLJS_ARGUMENT_TYPE_CHECK(args[0],
IsString,
"Bad Argument: parseString requires a string");

That's in XmlSaxParser::Push(const v8::Arguments& args)

The issue appears to be with LIBXMLJS_ARGUMENT_TYPE_CHECK, it always evaluates to true, even when I pass the method something like parser.push(new String("hello"));

FreeBSD XPath problem

I have a problem with using find/get methods even in simplest cases. It just returns "undefined" results. Even example test case doesn't work. I'm using FreeBSD 8.1, libxmljs 0.4.2, node 0.4.8 and libxml 2.7.8.

Reusing sax parser causes segfault after GC

from spec_xml_sax_parser.js test script

it('can can be reused as a file parser', function() {
    var parser = createParser('SaxParser');

    for (var i=0; i<10; i++) {
        gc();
        parser.parseFile(filename);
    }

    assert.ok(true);
});

segfault after the first interation.

Installation via npm fails on Cygwin

Hi,

I'm completely new to node.js and libxmljs. Tried to install it under Windows 7 using Cygwin, but it failed. Any idea what went wrong?

Versions:
node.js: 0.2.6
npm: 0.2.16
scons: 2.0.1

Dump:

$ npm install libxmljs
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info preinstall [email protected]
scons: Reading SConscript files ...
OSError: [Errno 2] No such file or directory:
  File "/usr/local/lib/node/.npm/libxmljs/0.4.1/package/SConstruct", line 43:
    cflags = shellOut([xml2config, '--cflags'])
  File "/usr/local/lib/node/.npm/libxmljs/0.4.1/package/SConstruct", line 19:
    return subprocess.Popen(target, stdout=subprocess.PIPE).communicate()[0].strip()
  File "/usr/lib/python2.6/subprocess.py", line 633:
    errread, errwrite)
  File "/usr/lib/python2.6/subprocess.py", line 1139:
    raise child_exception
make: *** [node] Error 2
npm info [email protected] Failed to exec preinstall script
npm ERR! install failed Error: [email protected] preinstall: `make node`
npm ERR! install failed `sh` failed with 2
npm ERR! install failed     at ChildProcess. (/usr/local/lib/node/.npm/npm/0.2.16/package/lib/utils/exec.js:25:18)
npm ERR! install failed     at ChildProcess.emit (events:34:17)
npm ERR! install failed     at ChildProcess.onexit (child_process:168:12)
npm ERR! install failed     at node.js:773:9
npm info install failed rollback
npm info uninstall [ '[email protected]' ]
npm info preuninstall [email protected]
scons: Reading SConscript files ...
OSError: [Errno 2] No such file or directory:
  File "/usr/local/lib/node/.npm/libxmljs/0.4.1/package/SConstruct", line 43:
    cflags = shellOut([xml2config, '--cflags'])
  File "/usr/local/lib/node/.npm/libxmljs/0.4.1/package/SConstruct", line 19:
    return subprocess.Popen(target, stdout=subprocess.PIPE).communicate()[0].strip()
  File "/usr/lib/python2.6/subprocess.py", line 633:
    errread, errwrite)
  File "/usr/lib/python2.6/subprocess.py", line 1139:
    raise child_exception
make: *** [clean] Error 2
npm ERR! [email protected] Error: `sh` failed with 2
npm ERR! [email protected]     at ChildProcess. (/usr/local/lib/node/.npm/npm/0.2.16/package/lib/utils/exec.js:25:18)
npm ERR! [email protected]     at ChildProcess.emit (events:34:17)
npm ERR! [email protected]     at ChildProcess.onexit (child_process:168:12)
npm ERR! [email protected]     at node.js:773:9
npm ERR! [email protected] failed, but continuing anyway
npm info uninstall [email protected]
npm info auto-deactive not symlink
npm info postuninstall [email protected]
npm info uninstall [email protected] complete
npm info install failed rolled back
npm ERR! Error: [email protected] preinstall: `make node`
npm ERR! `sh` failed with 2
npm ERR!     at ChildProcess. (/usr/local/lib/node/.npm/npm/0.2.16/package/lib/utils/exec.js:25:18)
npm ERR!     at ChildProcess.emit (events:34:17)
npm ERR!     at ChildProcess.onexit (child_process:168:12)
npm ERR!     at node.js:773:9
npm ERR!
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is most likely a problem with the libxmljs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     make node
npm ERR! You can get their info via:
npm ERR!     npm owner ls libxmljs

Weird behavior when adding attribute

When using elem.attr(new_atttr) where new_attr is a libxmljs Attribute object, you get not only the attribute value but all of the public properties of the attribute object on the element.

<?xml version="1.0" encoding="UTF-8"?>
<foo tal:attr="fizz:'buzz'" fizz="buzz" name="function name() { [native code] }" value="function value() { [native code] }" node="function node() { [native code] }" doc="function doc() { [native code]}" parent="function parent() { [native code] }" namespace="function namespace() { [native code] }" prevSibling="function prevSibling() { [native code] }" nextSibling="function nextSibling() {[native code] }" type="function type() { [native code] }" remove="function remove() { [native code] }" toString="function toString() { [native code] }">This is a foo node.</foo>

scons libxmljs.node compile error

scons: Reading SConscript files ...
Checking for node.js ...(cached) yes
True
Checking for C++ library xml2... (cached) yes
Checking for node.js ...(cached) yes
TypeError: Directory /Users/eric/workspace/libxmljs/libxmljs found where file expected.:
File "/Users/eric/workspace/libxmljs/SConstruct", line 85:
LIBPATH = libpath
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/scons-1.3.0/SCons/Environment.py", line 260:
return apply(MethodWrapper.call, (self, target, source) + args, kw)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/scons-1.3.0/SCons/Environment.py", line 224:
return apply(self.method, nargs, kwargs)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/scons-1.3.0/SCons/Builder.py", line 632:
return self._execute(env, target, source, OverrideWarner(kw), ekw)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/scons-1.3.0/SCons/Builder.py", line 553:
tlist, slist = self._create_nodes(env, target, source)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/scons-1.3.0/SCons/Builder.py", line 500:
tlist = env.arg2nodes(target, target_factory, target=target, source=source)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/scons-1.3.0/SCons/Environment.py", line 484:
v = node_factory(apply(self.subst, (v,), kw))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/scons-1.3.0/SCons/Node/FS.py", line 1274:
return self._lookup(name, directory, File, create)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/scons-1.3.0/SCons/Node/FS.py", line 1253:
return root._lookup_abs(p, fsclass, create)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/scons-1.3.0/SCons/Node/FS.py", line 2123:
result.diskcheck_match()
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/scons-1.3.0/SCons/Node/FS.py", line 2269:
"Directory %s found where file expected.")
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/lib/scons-1.3.0/SCons/Node/FS.py", line 410:
raise TypeError, errorfmt % node.abspath

MacOS Snow Leopard

npm install fails on Ubuntu 10.04 LTS

npm install fails on Ubuntu 10.04 LTS after upgrading node and npm to latest versions.

As I'm a linux newb I imagine it's my fault rather than yours. But npm asked me nicely to post this here so...

> [email protected] preinstall /home/edwin/node/node_modules/libxmljs
> make node

scons: Reading SConscript files ...
Checking for node.js ...(cached) yes
True
Checking for C++ library xml2... yes
Checking for node.js ...(cached) yes
scons: done reading SConscript files.
scons: Building targets ...
g++ -o src/html_document.os -c -I/usr/include/libxml2 -g -O2 -rdynamic -D_GNU_SOURCE -DHAVE_CONFIG_H=1 -pthread -m32 -g -O3 -DHAVE_OPENSSL=1 -DEV_FORK_ENABLE=0 -DEV_EMBED_ENABLE=0 -DEV_MULTIPLICITY=0 -DX_STACKSIZE=65536 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DEV_MULTIPLICITY=0 -DHAVE_FDATASYNC=1 -DPLATFORM="linux" -D__POSIX__=1 -Wno-unused-parameter -D_FORTIFY_SOURCE=2 -I/usr/include/node -fPIC src/html_document.cc
In file included from src/html_document.h:5,
                 from src/html_document.cc:2:
src/libxmljs.h:5:16: error: v8.h: No such file or directory
src/libxmljs.h:6:18: error: node.h: No such file or directory
In file included from src/libxmljs.h:98,
                 from src/html_document.h:5,
                 from src/html_document.cc:2:
src/object_wrap.h:9: error: 'node' has not been declared
src/object_wrap.h:9: error: expected '{' before 'ObjectWrap'
src/object_wrap.h:9: error: invalid type in declaration before '{' token
src/object_wrap.h:9: warning: extended initializer lists only available with -std=c++0x or -std=gnu++0x
src/object_wrap.h:10: error: expected primary-expression before 'public'
src/object_wrap.h:10: error: expected '}' before 'public'
src/object_wrap.h:10: error: expected ',' or ';' before 'public'
src/html_document.cc:9: error: expected '}' at end of input
scons: *** [src/html_document.os] Error 1
scons: building terminated because of errors.
make: *** [node] Error 2
npm ERR! error installing [email protected] Error: [email protected] preinstall: `make node`
npm ERR! error installing [email protected] `sh "-c" "make node"` failed with 2
npm ERR! error installing [email protected]     at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/lib/utils/exec.js:49:20)
npm ERR! error installing [email protected]     at ChildProcess.emit (events.js:67:17)
npm ERR! error installing [email protected]     at ChildProcess.onexit (child_process.js:192:12)

> [email protected] preuninstall /home/edwin/node/node_modules/libxmljs
> make clean

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Cleaning targets ...
scons: done cleaning targets.
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Cleaning targets ...
scons: done cleaning targets.
npm ERR! [email protected] preinstall: `make node`
npm ERR! `sh "-c" "make node"` failed with 2
npm ERR!
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is most likely a problem with the libxmljs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     make node
npm ERR! You can get their info via:
npm ERR!     npm owner ls libxmljs
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Linux 2.6.32-32-generic
npm ERR! command "node" "/usr/bin/npm" "install" "libxmljs"
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /home/edwin/node/npm-debug.log
npm not ok

npm install errors out

I tried installing libxmljs via npm an ran into an error:

mobius:libxmljs dave$ npm install libxmljs
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info preinstall [email protected]
make: scons: Command not found
make: *** [node] Error 127
npm info [email protected] Failed to exec preinstall script
npm ERR! install failed Error: [email protected] preinstall: make node
npm ERR! install failed sh failed with 2
npm ERR! install failed at ChildProcess. (/usr/local/lib/node/.npm/npm/0.2.10-1/package/lib/utils/exec.js:24:18)
npm ERR! install failed at ChildProcess.emit (events.js:34:17)
npm ERR! install failed at ChildProcess.onexit (child_process.js:164:12)
npm info install failed rollback
npm info uninstall [ '[email protected]' ]
npm info preuninstall [email protected]
make: scons: Command not found
make: *** [clean] Error 127
npm ERR! [email protected] Error: sh failed with 2
npm ERR! [email protected] at ChildProcess. (/usr/local/lib/node/.npm/npm/0.2.10-1/package/lib/utils/exec.js:24:18)
npm ERR! [email protected] at ChildProcess.emit (events.js:34:17)
npm ERR! [email protected] at ChildProcess.onexit (child_process.js:164:12)
npm ERR! [email protected] failed, but continuing anyway
npm ERR! rollback failed Error: sh failed with 2
npm ERR! rollback failed at ChildProcess. (/usr/local/lib/node/.npm/npm/0.2.10-1/package/lib/utils/exec.js:24:18)
npm ERR! rollback failed at ChildProcess.emit (events.js:34:17)
npm ERR! rollback failed at ChildProcess.onexit (child_process.js:164:12)
npm ERR! Error: [email protected] preinstall: make node
npm ERR! sh failed with 2
npm ERR! at ChildProcess. (/usr/local/lib/node/.npm/npm/0.2.10-1/package/lib/utils/exec.js:24:18)
npm ERR! at ChildProcess.emit (events.js:34:17)
npm ERR! at ChildProcess.onexit (child_process.js:164:12)
npm ERR!
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is most likely a problem with the libxmljs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! make node
npm ERR! You can get their info via:
npm ERR! npm owner ls libxmljs
npm ERR! There may be additional logging output above.
npm not ok
mobius:libxmljs dave$

Any ideas on what's going on here? I think it's an issue with "scons".

Thanks,
Dave

Memory allocator

How about using V8 memory allocator for libxml?
I've seen that you are using xmlMemSetup in InitializeLibXMLJS, but it sets default functions for libxml.
Maybe should try to change these defaults to allocation methods from v8?
That is, it turns out that all memory will be allocated using v8.
If this can be done, you can then remove the code for memory management of libxmljs such as UpdateV8Memory, V8::AdjustAmountOfExternalAllocatedMemory and others.

Memory leak with attributes?

This leaks:

var libxml = require('libxmljs');

while (true) {
  new libxml.Document(function(n) {
    n.node('element', {'attr': 'test'}, 'value');
  });
}

But this one doesn't:

var libxml = require('libxmljs');

while (true) {
  new libxml.Document(function(n) {
    n.node('element', 'value');
  });
}

So I guess there is something wrong around arguments.

Tested on e52b22b, libxml2 2.6.32.dfsg-5+lenny1, nodejs v0.1.103.

Make on joyent no.de fails due to libxml2 not found

In a Joyent no.de account, do the following:

pkgin install libxml2; pkgin cl; pkgin -y in scons
npm install libxmljs

This will fail. So I grabbed the files and went directly to run make with:

npm cache add [email protected]
cd ~/.node_libraries/.npm/.cache/libxmljs/0.4.1/package
make

This results in:

scons: Reading SConscript files ...
Checking for node.js ...(cached) yes
True
Checking for C++ library xml2... no
Did not find libxml2, exiting!
make: *** [node] Error 1

It turns out that the joyent environment puts the libraries at /lib, so I tried adding '/lib' to the libpath in SConstruct, but that didn't help. I'm guessing there is some other path, perhaps for the include files, that needs to be tweaked too.

Parsing documents with encoding other than utf-8

There are problems parsing XML documents in encoding, other than utf-8, for example in windows-1251.
Comparing with python binding: parser opens document, recognizes encoding and returns all strings from document as unicode objects, properly converted from document encoding. When I need to modify document, I set new strings as unicode objects also, and during serialization to XML string they converted to the right encoding with respect to encoding property of the document.
This (or something similar) doesn't happen when working with such documents from node.js.

allow callback for larger parsing jobs

xml parsing can be time-intensive for large documents; is it possible to offer a callback on parseXmlFile and parseXmlString? This would help me out using the library with node.js.

integers ignored as element content

It seems document nodes with integers (and probably all non-strings) as content ignore the integers. The following code:

var libxml = require("libxmljs");
var sys = require("sys");

var doc = {
  id: "1",
  fizzbuzz_t: "foo",
  wakak_i: 5
};

var xmldoc = new libxml.Document(function (n) {
  n.node("doc", function (n) {
    for (field in doc) {
      n.node("field", {name: field}, doc[field]);
    }
  });
});

var xmldoc2 = new libxml.Document(function (n) {
  n.node("doc", function (n) {
    for (field in doc) {
      n.node("field", {name: field}, String(doc[field]));
    }
  });
});

sys.puts(xmldoc.toString());
sys.puts(xmldoc2.toString());

Gives the following result:

$ node libxml-int.js 
<?xml version="1.0" encoding="UTF-8"?>
<doc><field name="id">1</field><field name="fizzbuzz_t">foo</field><field name="wakak_i"/></doc>

<?xml version="1.0" encoding="UTF-8"?>
<doc><field name="id">1</field><field name="fizzbuzz_t">foo</field><field     name="wakak_i">5</field></doc>

$ 

Notice that the first document silently drops the content for "wakak_i". Should I wrap all content in String() or should libxmljs handle integers there?

build issues libxml2 not detected

Hi compiling on Mac 10.6.x with mac ports installed libxml2.

Here is the error I get when running scons. I have nodejs node-v0.1.94 installed.

  libxmljs> scons
  scons: Reading SConscript files ...
  /usr/local/lib/scons-1.0.1/SCons/Platform/posix.py:38: DeprecationWarning: The popen2 module    is deprecated.  Use the subprocess module.
    import popen2
   /usr/local/lib/scons-1.0.1/SCons/Tool/msvs.py:37: DeprecationWarning: the md5 module is    deprecated; use hashlib instead
    import md5
  Checking for node.js ...(cached) yes
   True
  Checking for C++ library xml2... no
  Did not find libxml2, exiting!

And here is where libxml2 is installed from macports:

ls -lh /opt/local/lib/libxml2*
-rwxr-xr-x 2 root admin 1.2M 2009-02-07 14:48 /opt/local/lib/libxml2.2.7.3.dylib*
 lrwxr-xr-x 1 root admin   19 2009-02-07 14:48 /opt/local/lib/libxml2.2.dylib -> libxml2.2.7.3.dylib*
-rw-r--r-- 2 root admin 1.6M 2009-02-07 14:48 /opt/local/lib/libxml2.a
lrwxr-xr-x 1 root admin   19 2009-02-07 14:48 /opt/local/lib/libxml2.dylib -> libxml2.2.7.3.dylib*
-rwxr-xr-x 2 root admin  866 2009-02-07 14:48 /opt/local/lib/libxml2.la*


 ls -lh /opt/local/include/libxml2/
 total 0
 drwxr-xr-x 49 root admin 1.7K 2009-02-07 14:48 libxml/

Memory tag error / xmlMemFree(...) error

I'm on Mac OS X 10.6.3 (an iMac),

I just compile libxmljs with fresh node.js, libxml2 and scons:

  • node v0.1.98-31-g1c6671a (from github)
  • scons @1.3.0 (from macport)
  • libxml2 @2.7.7 (from macport)

My javascript file is fairly simple, only one line:

  var libxml = require('./libxmljs');

But, when I run this file with node, I got the following error right away:

Memory tag error occurs :0x100701788 
     bye
xmlMemFree(1007017B0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x100701798 
     bye
xmlMemFree(1007017C0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x100701418 
     bye
xmlMemFree(100701440) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x100701758 
     bye
xmlMemFree(100701780) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x100701408 
     bye
xmlMemFree(100701430) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x100701728 
     bye
xmlMemFree(100701750) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x1007013f8 
     bye
xmlMemFree(100701420) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x1007016f8 
     bye
xmlMemFree(100701720) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x1007013b8 
     bye
xmlMemFree(1007013E0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x1007013c8 
     bye
xmlMemFree(1007013F0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x100700de8 
     bye
xmlMemFree(100700E10) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x100701388 
     bye
xmlMemFree(1007013B0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x100700dd8 
     bye
xmlMemFree(100700E00) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x100701358 
     bye
xmlMemFree(100701380) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x100700a88 
     bye
xmlMemFree(100700AB0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x100701328 
     bye
xmlMemFree(100701350) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x100701198 
     bye
xmlMemFree(1007011C0) error
xmlMallocBreakpoint reached on block 0

Any clue what could cause this error ?

By the way, I try with another machine (my MacBook) and I got exactly the same error.

Thanks.

doc.get fails on newsML html node

I'm trying to get libxmljs to parse NewsML to (among other things) extract the html article content. But, when I try and do a doc.get to grab the html node, libxmljs returns nothing. doc.get works perfectly fine for other things, in fact I can get the parent of the html node successfully. Is this a libxmljs or a libxml problem?

Here's a simplified version of what I'm trying to do (I've significantly stripped down the XML):

var libxmljs = require('libxmljs');

var xml = '<?xml version="1.0" encoding="ISO-8859-1"?>' +
            '<!DOCTYPE NewsML SYSTEM "../DTD/NewsMLv1.0.dtd" [<!ENTITY % html SYSTEM "../DTD/xhtml1-strict.dtd">]>' +
            '<NewsML>' +
            '   <NewsItem>' +
            '       <NewsComponent Duid="wrapper" Essential="no" EquivalentsList="no">' +
            '           <NewsComponent Duid="text" Essential="no" EquivalentsList="no">' +
            '               <ContentItem>' +
            '                   <DataContent>' +
            '                       <html xmlns="http://www.w3.org/1999/xhtml">' +
            '                           <head>' +
            '                               <title/>' +
            '                           </head>' +
            '                           <body>' +
            '                               <p>This is some text.</p>' +
            '                           </body>' +
            '                       </html>' +
            '                   </DataContent>' +
            '               </ContentItem>' +
            '           </NewsComponent>' +
            '       </NewsComponent>' +
            '   </NewsItem>' +
            '</NewsML>';

var doc = libxmljs.parseXmlString(xml);
var dataContentNode = doc.get('//DataContent');
var htmlNode = doc.get('//html');

console.log(dataContentNode.toString()); // correctly returns the dataContent node and all children
console.log(htmlNode.toString()); // fails because htmlNode is undefined

npm install fails on Mac OS X

$ node --version
v0.4.7
$ npm --version
1.0.6
$ uname -a
Darwin tippy.local 10.7.0 Darwin Kernel Version 10.7.0: Sat Jan 29 15:17:16 PST 2011; root:xnu-1504.9.37~1/RELEASE_I386 i386
$ g++ --version
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ npm install libxmljs

[email protected] preinstall /Users/davidherron/Node.JS/node_modules/libxmljs
make node

scons: Reading SConscript files ...
Checking for node.js ...(cached) yes
True
Checking for C++ library xml2... yes
Checking for node.js ...(cached) yes
scons: done reading SConscript files.
scons: Building targets ...
g++ -o src/html_document.os -c -I/opt/local/include/libxml2 -rdynamic -D_GNU_SOURCE -DHAVE_CONFIG_H=1 -pthread -arch x86_64 -g -O3 -DHAVE_OPENSSL=1 -DEV_FORK_ENABLE=0 -DEV_EMBED_ENABLE=0 -DEV_MULTIPLICITY=0 -DX_STACKSIZE=65536 -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DEV_MULTIPLICITY=0 -DHAVE_FDATASYNC=0 -DPLATFORM="darwin" -D__POSIX__=1 -Wno-unused-parameter -D_FORTIFY_SOURCE=2 -DNDEBUG -I/Users/david/node.js/0.4.7/include/node -fPIC src/html_document.cc
In file included from src/html_document.h:5,
from src/html_document.cc:2:
src/libxmljs.h:5:16: error: v8.h: No such file or directory
src/libxmljs.h:6:18: error: node.h: No such file or directory
In file included from src/libxmljs.h:98,
from src/html_document.h:5,
from src/html_document.cc:2:
src/object_wrap.h:9: error: 'node' has not been declared
src/object_wrap.h:9: error: expected {' before 'ObjectWrap' src/object_wrap.h:9: error: function definition does not declare parameters In file included from src/html_document.h:6, from src/html_document.cc:2: src/xml_document.h:9: error: invalid use of incomplete type 'class libxmljs::LibXmlObj' src/object_wrap.h:9: error: forward declaration of 'class libxmljs::LibXmlObj' src/xml_document.h:15: error: 'v8' has not been declared src/xml_document.h:15: error: ISO C++ forbids declaration of 'Persistent' with no type src/xml_document.h:15: error: expected ';' before '<' token src/xml_document.h:17: error: 'v8' has not been declared src/xml_document.h:17: error: expected ',' or '...' before '<' token src/xml_document.h:18: error: 'v8' has not been declared src/xml_document.h:18: error: ISO C++ forbids declaration of 'Persistent' with no type src/xml_document.h:18: error: expected ';' before '<' token src/xml_document.h:22: error: 'v8' has not been declared src/xml_document.h:22: error: ISO C++ forbids declaration of 'Handle' with no type src/xml_document.h:22: error: expected ';' before '<' token src/xml_document.h:23: error: 'v8' has not been declared src/xml_document.h:23: error: ISO C++ forbids declaration of 'Handle' with no type src/xml_document.h:23: error: expected ';' before '<' token src/xml_document.h:24: error: 'v8' has not been declared src/xml_document.h:24: error: ISO C++ forbids declaration of 'Handle' with no type src/xml_document.h:24: error: expected ';' before '<' token src/xml_document.h:25: error: 'v8' has not been declared src/xml_document.h:25: error: ISO C++ forbids declaration of 'Handle' with no type src/xml_document.h:25: error: expected ';' before '<' token src/xml_document.h:26: error: 'v8' has not been declared src/xml_document.h:26: error: ISO C++ forbids declaration of 'Handle' with no type src/xml_document.h:26: error: expected ';' before '<' token src/xml_document.h:27: error: 'v8' has not been declared src/xml_document.h:27: error: ISO C++ forbids declaration of 'Handle' with no type src/xml_document.h:27: error: expected ';' before '<' token src/xml_document.h:28: error: 'v8' has not been declared src/xml_document.h:28: error: ISO C++ forbids declaration of 'Handle' with no type src/xml_document.h:28: error: expected ';' before '<' token src/xml_document.h:32: error: 'v8' has not been declared src/xml_document.h:32: error: ISO C++ forbids declaration of 'Handle' with no type src/xml_document.h:32: error: expected ';' before '<' token src/xml_document.h:33: error: 'v8' has not been declared src/xml_document.h:33: error: ISO C++ forbids declaration of 'Handle' with no type src/xml_document.h:33: error: expected ';' before '<' token src/xml_document.h:34: error: 'v8' has not been declared src/xml_document.h:34: error: ISO C++ forbids declaration of 'Handle' with no type src/xml_document.h:34: error: expected ';' before '<' token src/xml_document.h:35: error: 'v8' has not been declared src/xml_document.h:35: error: ISO C++ forbids declaration of 'Handle' with no type src/xml_document.h:35: error: expected ';' before '<' token In file included from src/html_document.cc:2: src/html_document.h:14: error: 'v8' has not been declared src/html_document.h:14: error: expected ',' or '...' before '<' token src/html_document.cc:7: error: variable or field 'Initialize' declared void src/html_document.cc:7: error: 'v8' has not been declared src/html_document.cc:7: error: 'v8' has not been declared src/html_document.cc:7: error: 'target' was not declared in this scope scons: *** [src/html_document.os] Error 1 scons: building terminated because of errors. make: *** [node] Error 2 npm ERR! error installing [email protected] Error: [email protected] preinstall:make node npm ERR! error installing [email protected]sh "-c" "make node"` failed with 2
npm ERR! error installing [email protected] at ChildProcess. (/Users/davidherron/Node.JS/0.4.7/lib/node_modules/npm/lib/utils/exec.js:49:20)
npm ERR! error installing [email protected] at ChildProcess.emit (events.js:67:17)
npm ERR! error installing [email protected] at ChildProcess.onexit (child_process.js:192:12)

[email protected] preuninstall /Users/davidherron/Node.JS/node_modules/libxmljs
make clean

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Cleaning targets ...
scons: done cleaning targets.
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Cleaning targets ...
scons: done cleaning targets.
npm ERR! [email protected] preinstall: make node
npm ERR! sh "-c" "make node" failed with 2
npm ERR!
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is most likely a problem with the libxmljs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! make node
npm ERR! You can get their info via:
npm ERR! npm owner ls libxmljs
npm ERR! There is likely additional logging output above.
npm ERR!
npm ERR! System Darwin 10.7.0
npm ERR! command "node" "/Users/davidherron/Node.JS/0.4.7/bin/npm" "install" "libxmljs"
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR! /Users/davidherron/Node.JS/affiliates/linkshare/npm-debug.log
npm not ok

namespace prefix and parseXmlString

Example xml:

<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">/soap:Envelope

So if I parse this using libxml.parseXmlString and then try to find the envelope node using a namespace doc.find("soap:Envelope");

I get the following error.

XPath error : Undefined namespace prefix
xmlXPathEval: evaluation failed

If I build the xml doc using doc.node etc I can successfully select nodes with xpath that have namespaces.

Unfortunately I need to parse a string :(

new libxml.Element not working as per docs

new libxml.Element(doc, name, content) does not work as per docs:

// (doc, name, content) = content is dropped
var newnode = new libxml.Element(document, 'em', 'wink!');
sys.puts(newnode);

<em/>

// (doc, name, attr, content) = correct
var newnode = new libxml.Element(document, 'em', {}, 'wink!');
sys.puts(newnode);

<em>wink!</em>

thx!

Installing via npm without scons present doesn't break cleanly

Attempting to install libxmljs on a system without scons present fails with:
make: scons: No such file or directory
make: *** [node] Error 1
However, after installing scons and attempting to rebuild, npm seems to think that libxmljs was successfully installed. Attempting to uninstall via npm results in:
npm fail Couldn't remove version 0.4.0
npm ! Error: ENOENT, No such file or directory
at node.js:221:9
The workaround seems to be deleting ~/.node_libraries/.npm/libxmljs, after which it can be sucessfully rebuilt.

EXC_BAD_ACCESS in XmlSaxParser::releaseContext

Segmentation fault at line 57 of xml_sax_parser.cc:
context_->_private = 0;

XmlSaxParser::releaseContext is called from the destructor but if initializeContext was not previously executed the result is EXC_BAD_ACCESS.

This happens when a new parser is created but never used and the garbage collector kicks in.

Memory tag error

I have built libxmljs for use with node.

If I require("./libxmljs") I get errors and my node app closes (I have included the errors at the bottom of this issue)

(I use libxml2-2.7.2 and node 0.1.100 )

Memory tag error occurs :0x964e6e0
bye
xmlMemFree(964E6F8) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x964e6f0
bye
xmlMemFree(964E708) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x964e6b8
bye
xmlMemFree(964E6D0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x964e6c8
bye
xmlMemFree(964E6E0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x964e690
bye
xmlMemFree(964E6A8) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x964e6a0
bye
xmlMemFree(964E6B8) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x964e668
bye
xmlMemFree(964E680) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x964e678
bye
xmlMemFree(964E690) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x964e640
bye
xmlMemFree(964E658) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x964e650
bye
xmlMemFree(964E668) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x964e618
bye
xmlMemFree(964E630) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x964e628
bye
xmlMemFree(964E640) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x962d3d8
bye
xmlMemFree(962D3F0) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x964e600
bye
xmlMemFree(964E618) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x962cff8
bye
xmlMemFree(962D010) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x964e5e8
bye
xmlMemFree(964E600) error
xmlMallocBreakpoint reached on block 0
Memory tag error occurs :0x964e518
bye
xmlMemFree(964E530) error

Segfault when using XML Builder

I'm getting a segmentation fault when using the XML builder functions. This apparently happens after the garbage collector runs (I can see the memory tag errors right before the crash). Here's what it says:

*** glibc detected *** node: corrupted double-linked list: 0x0a29d0f8 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6(+0x6b591)[0xb74b5591]
/lib/tls/i686/cmov/libc.so.6(+0x6b9ea)[0xb74b59ea]
/lib/tls/i686/cmov/libc.so.6(+0x6cd65)[0xb74b6d65]
/lib/tls/i686/cmov/libc.so.6(cfree+0x6d)[0xb74b9ecd]
/usr/lib/libxml2.so.2(xmlMemFree+0xe1)[0xb488cd71]
/usr/local/lib/node/.npm/libxmljs/0.4.1/package/libxmljs.node(_ZN8libxmljs11XmlDocument9to_stringEv+0x8e)[0xb4a517ce]
/usr/local/lib/node/.npm/libxmljs/0.4.1/package/libxmljs.node(_ZN8libxmljs11XmlDocument8ToStringERKN2v89ArgumentsE+0x5c)[0xb4a51a1c]

I don't know if the memory map is of any help, but I can post that too if so. This is under Ubuntu 10.04.

Failed preinstall script

$ npm install libxmljs
npm info it worked if it ends with ok
npm info using [email protected]
npm info using [email protected]
npm info fetch http://registry.npmjs.org/libxmljs/-/libxmljs-0.4.1.tgz
npm info calculating sha1 /Users/andrew/node/lib/node/.npm/.cache/libxmljs/0.4.1/package.tgz
npm info shasum 464b8896fa4dc1c35e15104c32fa59ad37b6d869
npm info preinstall [email protected]
make: scons: No such file or directory
make: *** [node] Error 1
npm info [email protected] Failed to exec preinstall script
npm ERR! install failed Error: [email protected] preinstall: `make node`
npm ERR! install failed `sh "-c" "make node"` failed with 2
npm ERR! install failed     at ChildProcess.<anonymous> (/Users/andrew/node/lib/node/.npm/npm/0.3.15/package/lib/utils/exec.js:49:20)
npm ERR! install failed     at ChildProcess.emit (events.js:45:17)
npm ERR! install failed     at ChildProcess.onexit (child_process.js:171:12)
npm info install failed rollback
npm info uninstall [ '[email protected]' ]
npm info preuninstall [email protected]
make: scons: No such file or directory
make: *** [clean] Error 1
npm ERR! [email protected] Error: `sh "-c" "make clean"` failed with 2
npm ERR! [email protected]     at ChildProcess.<anonymous> (/Users/andrew/node/lib/node/.npm/npm/0.3.15/package/lib/utils/exec.js:49:20)
npm ERR! [email protected]     at ChildProcess.emit (events.js:45:17)
npm ERR! [email protected]     at ChildProcess.onexit (child_process.js:171:12)
npm ERR! [email protected] failed, but continuing anyway
npm info uninstall [email protected]
npm info auto-deactive not symlink
npm info postuninstall [email protected]
npm info uninstall [email protected] complete
npm info install failed rolled back
npm ERR! Error: [email protected] preinstall: `make node`
npm ERR! `sh "-c" "make node"` failed with 2
npm ERR!     at ChildProcess.<anonymous> (/Users/andrew/node/lib/node/.npm/npm/0.3.15/package/lib/utils/exec.js:49:20)
npm ERR!     at ChildProcess.emit (events.js:45:17)
npm ERR!     at ChildProcess.onexit (child_process.js:171:12)
npm ERR! 
npm ERR! Failed at the [email protected] preinstall script.
npm ERR! This is most likely a problem with the libxmljs package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     make node
npm ERR! You can get their info via:
npm ERR!     npm owner ls libxmljs
npm ERR! There is likely additional logging output above.
npm ERR! System Darwin 10.7.0
npm ERR! argv { remain: [ 'libxmljs' ],
npm ERR! argv   cooked: [ 'install', 'libxmljs' ],
npm ERR! argv   original: [ 'install', 'libxmljs' ] }
npm not ok

something funny going on with element.name()

I can consistently cause a segmentation fault (in gdb) with a name tag. I run the server, load (using refresh) a page and it loads OK. I then reload the page and the seg fault occurs. (It consistently happens on the second page load).

The backtrace is at the bottom of this post.

The bit of code it occurs in is here:

            sys.puts('CeXmlNode: tagName')
    var n = this.libXmlNode 
            sys.puts('CeXmlNode: tagName: 2: ' + sys.inspect(n))
            for (var i in n) {
                  sys.puts(n[i])
            }
            sys.puts('** CeXmlNode: tagName: going to try to get the name now!!: ')
    var name = n.name()
            sys.puts('CeXmlNode: tagName: 3: ' + name)
    //return this.libXmlNode.name()
    return name

and the output looks like this: You can see that the element (n) seems to exist OK because I can iterate over its contents fine.

CeXmlNode: tagName
CeXmlNode: tagName: 2: {}
function addChild() { [native code] }
function () {
var args = libxml.Element.Arguments(arguments);
var elem = null;

if (args[0] instanceof libxml.Element)
elem = args[0];
else
elem = new libxml.Element(this.doc(), args[0], args[1], args[2], args[3]);

this.addChild(elem);
return elem;
}
function attr() { [native code] }
function () {
return this.find.apply(this, arguments)[0];
}
function () {
var args = arguments.length == 1 ? [null, arguments[0]] : [arguments[0], arguments[1]];
return new libxml.Namespace(this, args[0], args[1]);
}
function attrs() { [native code] }
function child() { [native code] }
function childNodes() { [native code] }
function find() { [native code] }
function nextElement() { [native code] }
function prevElement() { [native code] }
function name() { [native code] }
function path() { [native code] }
function text() { [native code] }
function addPrevSibling() { [native code] }
function addNextSibling() { [native code] }
function doc() { [native code] }
function parent() { [native code] }
function namespace() { [native code] }
function prevSibling() { [native code] }
function nextSibling() { [native code] }
function type() { [native code] }
function remove() { [native code] }
function toString() { [native code] }
CeXmlNode: tagName: 3: ceImport
CeXmlNode.getAttribute: 1
CeXmlNode.getAttribute: 4: 'selects/ProjectObjects.xml'
CeXmlNode.getAttribute: 1
CeXmlNode.getAttribute: 4: 'false'
CeXmlNode: tagName
CeXmlNode: tagName: 2: {}
function addChild() { [native code] }
function () {
var args = libxml.Element.Arguments(arguments);
var elem = null;

if (args[0] instanceof libxml.Element)
elem = args[0];
else
elem = new libxml.Element(this.doc(), args[0], args[1], args[2], args[3]);

this.addChild(elem);
return elem;
}
function attr() { [native code] }
function () {
return this.find.apply(this, arguments)[0];
}
function () {
var args = arguments.length == 1 ? [null, arguments[0]] : [arguments[0], arguments[1]];
return new libxml.Namespace(this, args[0], args[1]);
}
function attrs() { [native code] }
function child() { [native code] }
function childNodes() { [native code] }
function find() { [native code] }
function nextElement() { [native code] }
function prevElement() { [native code] }
function name() { [native code] }
function path() { [native code] }
function text() { [native code] }
function addPrevSibling() { [native code] }
function addNextSibling() { [native code] }
function doc() { [native code] }
function parent() { [native code] }
function namespace() { [native code] }
function prevSibling() { [native code] }
function nextSibling() { [native code] }
function type() { [native code] }
function remove() { [native code] }
function toString() { [native code] }
** CeXmlNode: tagName: going to try to get the name now!!:

Program received signal SIGSEGV, Segmentation fault.


== backtrace ==

Program received signal SIGSEGV, Segmentation fault.
0x0049a785 in ?? () from /lib/tls/i686/cmov/libc.so.6
(gdb) backtrace
#0 0x0049a785 in ?? () from /lib/tls/i686/cmov/libc.so.6
#1 0x081da73e in v8::internal::StrLength (string=0x8 <Address 0x8 out of bounds>)

at /home/ed/node/node-v0.1.97/deps/v8/src/utils.h:142

#2 0x081d66f5 in v8::String::New (data=0x8 <Address 0x8 out of bounds>, length=-1)

at /home/ed/node/node-v0.1.97/deps/v8/src/api.cc:3392

#3 0x006638aa in libxmljs::XmlElement::get_name (this=0x8601298) at src/xml_element.cc:298
#4 0x00663fa5 in libxmljs::XmlElement::Name (args=...) at src/xml_element.cc:79
#5 0x081f3ef1 in Builtin_Impl_FastHandleApiCall (args=...)

at /home/ed/node/node-v0.1.97/deps/v8/src/builtins.cc:1054

#6 0x081f3d06 in Builtin_FastHandleApiCall (args=...) at /home/ed/node/node-v0.1.97/deps/v8/src/builtins.cc:1014
#7 0x005961ee in ?? ()
#8 0x006353d4 in ?? ()
#9 0x005a9179 in ?? ()
#10 0x00596da2 in ?? ()
#11 0x0820b703 in Invoke (construct=false, func=..., receiver=..., argc=0, args=0x0,

has_pending_exception=0xbfffe3af) at /home/ed/node/node-v0.1.97/deps/v8/src/execution.cc:94

#12 0x0820b7ef in v8::internal::Execution::Call (func=..., receiver=..., argc=0, args=0x0,

pending_exception=0xbfffe3af) at /home/ed/node/node-v0.1.97/deps/v8/src/execution.cc:121

#13 0x082e7eab in v8::internal::Object::GetPropertyWithDefinedGetter (this=0xb5d8a479, receiver=0xb5d8a479,

getter=0xb5fd9c45) at /home/ed/node/node-v0.1.97/deps/v8/src/objects.cc:209

#14 0x082e7dcf in v8::internal::Object::GetPropertyWithCallback (this=0xb5d8a479, receiver=0xb5d8a479,

structure=0xb5d833e1, name=0xb5fbadbd, holder=0xb5d8a479)
at /home/ed/node/node-v0.1.97/deps/v8/src/objects.cc:185

#15 0x082e8b18 in v8::internal::Object::GetProperty (this=0xb5d8a479, receiver=0xb5d8a479, result=0xbfffe4e0,

name=0xb5fbadbd, attributes=0xbfffe504) at /home/ed/node/node-v0.1.97/deps/v8/src/objects.cc:501

#16 0x082c9949 in v8::internal::LoadIC::Load (this=0xbfffe568, state=v8::internal::PREMONOMORPHIC, object=...,

name=...) at /home/ed/node/node-v0.1.97/deps/v8/src/ic.cc:700

#17 0x082cba13 in v8::internal::LoadIC_Miss (args=...) at /home/ed/node/node-v0.1.97/deps/v8/src/ic.cc:1335
#18 0x005961ee in ?? ()
#19 0x005ea204 in ?? ()
#20 0x00597b9f in ?? ()
#21 0x005eaaa6 in ?? ()
#22 0x005eafc5 in ?? ()
#23 0x005eafc5 in ?? ()
#24 0x005eafc5 in ?? ()
#25 0x005eafc5 in ?? ()
#26 0x00597b9f in ?? ()
#27 0x005e9150 in ?? ()
#28 0x005e0fc5 in ?? ()
#29 0x007a5257 in ?? ()
#30 0x005e164d in ?? ()
#31 0x00597b9f in ?? ()
#32 0x007a13c6 in ?? ()
#33 0x005e1a18 in ?? ()
#34 0x005e0b26 in ?? ()
#35 0x0063f295 in ?? ()
#36 0x0063c352 in ?? ()
#37 0x00597b9f in ?? ()
#38 0x007a3593 in ?? ()
#39 0x005f4a4d in ?? ()
#40 0x005a9179 in ?? ()
#41 0x00596da2 in ?? ()
#42 0x0820b703 in Invoke (construct=false, func=..., receiver=..., argc=0, args=0x0,

has_pending_exception=0xbfffeadf) at /home/ed/node/node-v0.1.97/deps/v8/src/execution.cc:94

#43 0x0820b7ef in v8::internal::Execution::Call (func=..., receiver=..., argc=0, args=0x0,

pending_exception=0xbfffeadf) at /home/ed/node/node-v0.1.97/deps/v8/src/execution.cc:121

#44 0x081d40a6 in v8::Function::Call (this=0x85c0a10, recv=..., argc=0, argv=0x0)

at /home/ed/node/node-v0.1.97/deps/v8/src/api.cc:2669

#45 0x08182f54 in node::Parser::on_message_complete (p=0x85ffda4) at ../src/node_http_parser.cc:139
#46 0x081c8b68 in http_parser_execute (parser=0x85ffda4, settings=0x8578ca0,

data=0x86a7659 "POST /ceInfoSource.aspx?request=ceform&fid=nodeling_home_01&payload=&args=projectId:4&formId=&__=Thu%20Jun%2010%202010%2010%3A24%3A10%20GMT%2B0100%20(GMT%20Daylight%20Time) HTTP/1.1\r\nHost: u10\r\nUser-A"..., len=740) at ../deps/http_parser/http_parser.c:1366

#47 0x08184549 in node::Parser::Execute (args=...) at ../src/node_http_parser.cc:248

---Type to continue, or q to quit---
#48 0x081f5e47 in HandleApiCallHelper (args=...) at /home/ed/node/node-v0.1.97/deps/v8/src/builtins.cc:971
#49 0x081f3b9f in Builtin_Impl_HandleApiCall (args=...) at /home/ed/node/node-v0.1.97/deps/v8/src/builtins.cc:988
#50 0x081f3b85 in Builtin_HandleApiCall (args=...) at /home/ed/node/node-v0.1.97/deps/v8/src/builtins.cc:987
#51 0x005961ee in ?? ()
#52 0x005e7c21 in ?? ()
#53 0x0061d746 in ?? ()
#54 0x00597b9f in ?? ()
#55 0x005a9172 in ?? ()
#56 0x00596da2 in ?? ()
#57 0x0820b703 in Invoke (construct=false, func=..., receiver=..., argc=2, args=0xbfffefa4,

has_pending_exception=0xbfffef3f) at /home/ed/node/node-v0.1.97/deps/v8/src/execution.cc:94

#58 0x0820b7ef in v8::internal::Execution::Call (func=..., receiver=..., argc=2, args=0xbfffefa4,

pending_exception=0xbfffef3f) at /home/ed/node/node-v0.1.97/deps/v8/src/execution.cc:121

#59 0x081d40a6 in v8::Function::Call (this=0x85c07a8, recv=..., argc=2, argv=0xbfffefa4)

at /home/ed/node/node-v0.1.97/deps/v8/src/api.cc:2669

#60 0x0818b48a in node::IOWatcher::Callback (w=0x85ffc14, revents=1) at ../src/node_io_watcher.cc:55
#61 0x081bf499 in ev_invoke_pending () at ../deps/libev/ev.c:1997
#62 0x081bfef3 in ev_loop (flags=0) at ../deps/libev/ev.c:2359
#63 0x08176265 in Loop (args=...) at ../src/node.cc:1070
#64 0x081f5e47 in HandleApiCallHelper (args=...) at /home/ed/node/node-v0.1.97/deps/v8/src/builtins.cc:971
#65 0x081f3b9f in Builtin_Impl_HandleApiCall (args=...) at /home/ed/node/node-v0.1.97/deps/v8/src/builtins.cc:988
#66 0x081f3b85 in Builtin_HandleApiCall (args=...) at /home/ed/node/node-v0.1.97/deps/v8/src/builtins.cc:987
#67 0x005961ee in ?? ()
#68 0x005b0ec1 in ?? ()
#69 0x005a9179 in ?? ()
#70 0x00596da2 in ?? ()
#71 0x0820b703 in Invoke (construct=false, func=..., receiver=..., argc=1, args=0xbffff3cc,

has_pending_exception=0xbffff35f) at /home/ed/node/node-v0.1.97/deps/v8/src/execution.cc:94

#72 0x0820b7ef in v8::internal::Execution::Call (func=..., receiver=..., argc=1, args=0xbffff3cc,

pending_exception=0xbffff35f) at /home/ed/node/node-v0.1.97/deps/v8/src/execution.cc:121

#73 0x081d40a6 in v8::Function::Call (this=0x85c0790, recv=..., argc=1, argv=0xbffff3cc)

at /home/ed/node/node-v0.1.97/deps/v8/src/api.cc:2669

#74 0x0817c51e in Load (argc=3, argv=0xbffff864) at ../src/node.cc:1993
#75 0x0817cccc in main (argc=3, argv=0xbffff864) at ../src/node.cc:2183

(gdb)

New line at the beginning of XML string causes 'syntax error'

It's not valid XML but the error thrown doesn't help pin point the error at all. Looks as if the error type coming from the library is unexpected.

var doc = xmljs.parseXmlString("\n");

results in:

node: src/xml_syntax_error.cc:102: static v8::Handle<v8::Value> libxmljs::XmlSyntaxError::Getter(v8::Local<v8::String>, const v8::AccessorInfo&): Assertion `0 && "This shouldnt happen"' failed.

.find() returns array with undefined values mixed in with elements

I cannot figure out why I receive an array containing undefined values mixed in with the matched elements when doing a .find():

var libxmljs = require("libxmljs"),

  myxml = '<?xml version="1.0" encoding="UTF-8"?>'+
  '<ajax-response><response type="object" id="unknown">'+
  '<generic response="Success" message="Accepted" /></r'+
  'esponse></ajax-response>',

  xml = libxmljs.parseXmlString(myxml),
  res = xml.find('//generic');

console.log('Length: '+res.length);

for(var i=0; i<res.length; i++) {
  console.log('['+i+']'+(
    (typeof(res[i])=='undefined')?
      'Undefined value':
      res[i].toString()
  ));
}
  • Note there is no whitespace in the XML
  • It seems like the length should be 1 with the given XML and query
  • It seems like the returned array should contain "elements" or nothing
  • Multiple matches create additional undefined elements
  • Replicable on the most recent version tagged on github

Am I missing something? I tried to check if anyone else had this problem, and I read through all the documentation that I could find, and nothing mentions why this would be happening.

segfault when running Element.find

When querying some wsdl with libxmljs, I run 2 xpath querys successfully:

doc.find('//xs:schema',{'xs':'http://www.w3.org/2001/XMLSchema'});

schema.find('xs:element',{'xs':'http://www.w3.org/2001/XMLSchema'});

but node.js is segfualting on the following query (the node is an xs:element.

type.find('xs:complexType/xs:sequence/xs:element',{'xs':'http://www.w3.org/2001/XMLSchema'});

This error doesn't always occur on the same element. This is the error I get when running under gdb.

Program received signal SIGSEGV, Segmentation fault.

0x00613758 in libxmljs::XmlXpathContext::evaluate (this=0xbfffcdfc, 
    xpath=0x8492690 "xs:complexType/xs:sequence/xs:element") at src/xml_xpath_context.cc:36
36    v8::Handle nodes = v8::Array::New(result->nodesetval->nodeNr);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.