TobiasNickel / tXml

:zap:very small and fast xml-parser in pure javascript:zap:
MIT License
217 stars 28 forks source link

Unexpected close tag #39

Open GTCrais opened 2 years ago

GTCrais commented 2 years ago
const str = '<?xml version="1.0" encoding="UTF-8" ?>\n' +
'<xfdf xmlns="http://ns.adobe.com/xfdf/" xml:space="preserve">\n' +
'<fields />\n' +
'<add>\n' +
'<link page="0" rect="556.5,684.5,563,691" color="#000000" flags="print" name="f54cfadd-dc5a-126e-9512-e0812552a6a3" subject="Annotation" date="D:20220223101227+01\'00\'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="https://google.com"/></Action></OnActivation></link>\n' +
'<link page="0" rect="165.5,483,176,492" color="#000000" flags="print" name="4fc2499f-e94f-a45c-bfee-0cd68357f219" subject="Annotation" date="D:20220223101227+01\'00\'" width="0" style="solid"><OnActivation><Action Trigger="U"><URI Name="https://google.com"/></Action></OnActivation></link>\n' +
'<highlight page="0" rect="117.0469,461.6675,317.36563304933884,469.7305" color="#00CC63" flags="print" name="d5041f3b-57b9-5f66-8a33-15bc7b41b426" title="1" subject="Highlight" date="D:20220223101241+01\'00\'" creationdate="D:20220223101241+01\'00\'" coords="117.0469,469.7305,317.36563304933884,469.7305,117.0469,461.6675,317.36563304933884,461.6675"><contents>HI-does anyone know what the new program they are</contents></highlight>\n' +
'</add>\n' +
'<modify />\n' +
'<delete />\n' +
'</xfdf>';

const parsed= txml.parse(str);
Uncaught (in promise) Error: Unexpected close tag
Line: 4
Column: 289
Char: >
    at parseChildren (txml.mjs?a401:82:1)
    at parseNode (txml.mjs?a401:239:1)
    at parseChildren (txml.mjs?a401:138:1)
    at parseNode (txml.mjs?a401:239:1)
    at parseChildren (txml.mjs?a401:138:1)
    at parseNode (txml.mjs?a401:239:1)
    at parseChildren (txml.mjs?a401:138:1)
    at Module.parse (txml.mjs?a401:292:1)
    at eval (PdfPreview.vue?05a7:292:1)
TobiasNickel commented 2 years ago

link is in html usually an element that does not need to be closed. to the parse function, you can pass a second argument with options. in this case, the noChildNodes would be useful, you would pass an empty array there.