GithubHelp home page GithubHelp logo

Cannot get code working about xmldom HOT 6 OPEN

Delagen avatar Delagen commented on August 22, 2024
Cannot get code working

from xmldom.

Comments (6)

mbd-dbc-dk avatar mbd-dbc-dk commented on August 22, 2024

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?

from xmldom.

mbd-dbc-dk avatar mbd-dbc-dk commented on August 22, 2024

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?

from xmldom.

mbd-dbc-dk avatar mbd-dbc-dk commented on August 22, 2024

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

from xmldom.

madjic avatar madjic commented on August 22, 2024

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.

from xmldom.

JoeCodeswell avatar JoeCodeswell commented on August 22, 2024

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

from xmldom.

sergey-martynov avatar sergey-martynov commented on August 22, 2024

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

from xmldom.

Related Issues (20)

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.