Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot get code working #88

Open
Delagen opened this issue Apr 24, 2014 · 6 comments
Open

Cannot get code working #88

Delagen opened this issue Apr 24, 2014 · 6 comments

Comments

@Delagen
Copy link

Delagen commented Apr 24, 2014

The simple string is falled to exception
var string="123"
console.log((new DOMParser()).parseFromString(string, "text/xml"));

error "end tag name: root is not match the current start tagName:undefined"

@mbd-dbc-dk
Copy link

The string 123, is not actually valid XML though.

But, I have the same problem here for actual valid XML:

var doc = parser.parseFromString('xml', 'text/xml');
element parse error: TypeError: parseStack is undefined
@#[line:0,col:1]end tag name: my is not match the current start tagName:undefined
@#[line:1,col:2]============================================================

(This is loading the modules in either SpiderMonkey or Rhino, not in node.js - I have no idea how to load the current head in node.js).

Is there a mailing list for this project?

@mbd-dbc-dk
Copy link

More information about my troubles

This script:

load('dom.js');
load('dom-parser.js');
load('sax.js');

var doc = new DOMParser({
errorHandler:function(key,msg){
console.error(key, msg);
}
}).parseFromString('xml', 'text/xml');

Returns this under Rhino:

error element parse error: TypeError: Cannot read property "length" from undefined
@#[line:undefined,col:undefined]fatalError end tag name: some is not match the current start tagName:undefined
@#[line:undefined,col:undefined]Cannot read property "tagName" from undefined

And this under SpiderMonkey

error element parse error: TypeError: parseStack is undefined
@#[line:undefined,col:undefined]fatalError end tag name: some is not match the current start tagName:undefined
@#[line:undefined,col:undefined]============================================================
with this error stack:
Script engine error.
Place: 'Object::callFunction()'
ErrorReport:
13.16: TypeError: current is undefined
Error in 'dom-parser.js:113'

Stack:
((void 0),(void 0),"some")@dom-parser.js:113
parse("xml",[object Object],[object Object],[object Object],[object Object])@sax.js:107
("xml",[object Object],[object Object])@sax.js:31
("xml","text/xml")@dom-parser.js:25
test1()@dbc.js:22
@(interactive input):0

It would seem, that for some reason "parseStack" is not correctly set up.

Any clues from anyone?

@mbd-dbc-dk
Copy link

OK, I digged a bit further into it. It turns out, that you need to encapsulate each file when loading them. I was led by the conditional support of node.js (based on the presence of a require function) to think that you could just load them, and use them.

I think that is not actually possibly in the current form: both the file sax.js and the file dom-parser.js declares a global method called appendElement. No matter which order you load them in, one will overwrite the other, and you will get problems.

The error we see here, is because the sax file is loaded last. When its "appendElement" function is called, it will call stuff on the domBuilder, and the domBuilder will try to call its appendElement function, which takes two elements, but will hit the appendElement of the sax.js file, which requires three elements. The last argument is the parseStack, and it will be undefined, and the error comes from that.

I have added some information about how to fix this problem to the wiki, here:
https://github.com/jindw/xmldom/wiki/How-to-use-xmldom-in-non-node.js-JavaScript-platforms-like-Rhino-or-SpiderMonkey

@madjic
Copy link

madjic commented Apr 1, 2015

The workaround doesn't work in Nashorn.

I replaced loadObject with loadWithNewGlobal in the XMLDOM function, but then the dpObj will not load correctly,

var dpObj = loadWithNewGlobal(basePath + "/xmldom/dom-parser.js");
var dp_exports = {};
print('dpObj ' + dpObj + ', dp_exports ' + dp_exports);

prints

dpObj undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined, dp_exports [object Object]

but the dp_exports object seems to be empty.

@JoeCodeswell
Copy link

problems in running node.js

var doc = new dom().parseFromString(xml)
[xmldom error] element parse error: Error: invalid tagName:
@#[line:1,col:3]
[xmldom error] element parse error: Error: invalid tagName:
@#[line:13,col:2]
[xmldom error] element parse error: Error: invalid tagName:
@#[line:15,col:2]
[xmldom error] element parse error: Error: invalid tagName:
@#[line:17,col:2]
[xmldom error] element parse error: Error: invalid tagName:

...

the xml string is from an html file generated from an email

thanks for the help.
Love and peace,
Joew

@sergey-martynov
Copy link

@JoeCodeswell make sure that you have the file in the correct encoding (Most likely UTF-8)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants