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

Can not handle &xsd;string case in the xml #94

Open
kevinprotoss opened this issue Jun 17, 2014 · 4 comments
Open

Can not handle &xsd;string case in the xml #94

kevinprotoss opened this issue Jun 17, 2014 · 4 comments

Comments

@kevinprotoss
Copy link

Hello,

I used this module for parsing xml file which has the following data.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE owl [
     <!ENTITY tzont  "http://www.w3.org/2006/timezone#" >
     <!ENTITY owl  "http://www.w3.org/2002/07/owl#" >
     <!ENTITY xsd  "http://www.w3.org/2001/XMLSchema#" >
     <!ENTITY iso "http://www.daml.org/2001/09/countries/iso#" >
     <!ENTITY us-states "http://www.daml.ri.cmu.edu/ont/USRegionState.daml#" >
     <!ENTITY iso-3166-ont "http://www.daml.org/2001/09/countries/iso-3166-ont#" >
   ]>

<rdf:RDF
  xmlns    = "http://www.w3.org/2006/timezone-world#"
  xml:base    = "http://www.w3.org/2006/timezone-world"
  xmlns:tz-world = "http://www.w3.org/2006/timezone-world#"
  xmlns:tzont = "http://www.w3.org/2006/timezone#"
  xmlns:owl = "http://www.w3.org/2002/07/owl#"
  xmlns:rdf = "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
  xmlns:rdfs = "http://www.w3.org/2000/01/rdf-schema#"
  xmlns:iso = "http://www.daml.org/2001/09/countries/iso#"
  xmlns:us-states = "http://www.daml.ri.cmu.edu/ont/USRegionState.daml#"
  xmlns:iso-3166-ont = "http://www.daml.org/2001/09/countries/iso-3166-ont#"
  xmlns:xsd = "http://www.w3.org/2001/XMLSchema#">

<!-- intances of time zones -->

  <tzont:TimeZone rdf:ID="YTZ">
    <tzont:name rdf:datatype="&xsd;string">Yankee Time</tzont:name>
    <tzont:name rdf:datatype="&xsd;string">International Date Line West</tzont:name>
    <tzont:GMToffset rdf:datatype="&xsd;duration">-PT12H</tzont:GMToffset>
  </tzont:TimeZone>

</rdf:RDF>

However, all these &xsd; stuff can not be parsed by xmldom. I get this error from sax.js:

entity not found: `&xsd;string`

I think the xml is correct according to xml specification.

Best regards,
Kevin

@jindw
Copy link
Owner

jindw commented Aug 24, 2014

see: sax.parse(source,defaultNSMap,entityMap);
specify your entityMap yourself

it's new feature for xmldom: specify the entityMap on DOMParser constructor

@maisk
Copy link

maisk commented Sep 16, 2014

Feature request:
DOMParser option parameter entityMap.

if you replace the
var entityMap = {'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"}
with
var entityMap = options.entityMap ? options.entityMap : {'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"}
in source file dom-parser.js
at method:
DOMParser.prototype.parseFromString = function(source,mimeType)

i think is a good solution.

@codler
Copy link

codler commented Feb 5, 2017

A "options.entityMap" patch would be great! #131

@xZGit
Copy link

xZGit commented Apr 26, 2020

you can try this:

const XMLReader  = require('xmldome/sax').XMLReader
const oldParse = XMLReader.prototype.parse
const myEntityMap = {
    'times': '*'
};
XMLReader.prototype.parse =  function(source,defaultNSMap,entityMap){
   return oldParse.call(this, source, defaultNSMap, Object.assign(entityMap, myEntityMap));
};

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