Skip to content

Instantly share code, notes, and snippets.

@hgoebl
Created December 20, 2011 21:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hgoebl/1503453 to your computer and use it in GitHub Desktop.
Save hgoebl/1503453 to your computer and use it in GitHub Desktop.
handle non-utf8 encoded XML files
case S.PROC_INST_ENDING:
if (c === ">") {
emitNode(parser, "onprocessinginstruction", {
name : parser.procInstName,
body : parser.procInstBody
})
if (parser.procInstName === "xml") {
var match = parser.procInstBody.match(/encoding\s*=\s*['"]([A-Za-z_0-9-]+)['"]/)
if (match) parser.encoding = match[1]
}
parser.procInstName = parser.procInstBody = ""
parser.state = S.TEXT
} else {
parser.procInstBody += "?" + c
parser.state = S.PROC_INST_BODY
}
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment