From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/107307 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: Hans van der Meer Newsgroups: gmane.comp.tex.context Subject: Re: Is it possible to make xml.load a bit more 'verbose' when it encounters errors? Date: Thu, 14 May 2020 08:53:29 +0200 Message-ID: References: Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.14\)) Content-Type: multipart/mixed; boundary="===============2884898573543692164==" Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="96354"; mail-complaints-to="usenet@ciao.gmane.io" To: NTG ConTeXt Original-X-From: ntg-context-bounces@ntg.nl Thu May 14 08:53:54 2020 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane-mx.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by ciao.gmane.io with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZ7kg-000Ox7-S8 for gctc-ntg-context-518@m.gmane-mx.org; Thu, 14 May 2020 08:53:54 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 812F9183C34; Thu, 14 May 2020 08:53:34 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Agt7pC7ZeCeQ; Thu, 14 May 2020 08:53:32 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 7DEDE183C3D; Thu, 14 May 2020 08:53:32 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 875E7183C3A for ; Thu, 14 May 2020 08:53:31 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id DzBNqsGNgvP9 for ; Thu, 14 May 2020 08:53:30 +0200 (CEST) Received-SPF: Pass (mailfrom) identity=mailfrom; client-ip=212.54.42.167; helo=smtpq4.tb.mail.iss.as9143.net; envelope-from=havdmeer@ziggo.nl; receiver= Original-Received: from smtpq4.tb.mail.iss.as9143.net (smtpq4.tb.mail.iss.as9143.net [212.54.42.167]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 96E83183C34 for ; Thu, 14 May 2020 08:53:30 +0200 (CEST) Original-Received: from [212.54.42.110] (helo=smtp7.tb.mail.iss.as9143.net) by smtpq4.tb.mail.iss.as9143.net with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jZ7kI-0007ZG-CC for ntg-context@ntg.nl; Thu, 14 May 2020 08:53:30 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=ziggo.nl; s=202002corplgsmtpnl; h=To:Date:Subject:From; bh=KLO+EBRIls1eM+xLaQ4Eq2YylMwU+V8wxgLn16+Itlo=; b=XEd3MbyIZFdT6azgm1msr7dhCn Ex5EnvWRPrNpLaW3SN5FJ5P+0N9ecPFPAusD7Wn8HCw2/f4xPFvCZcHePaUHtuz4C96+/oKr1ZPbm ZfDMmcwxuUiCJTUmCTJhiZqnvAxAvz6F0hzcdHbVynJFMj1AQyQYyfvLwZE/2Qb+2J99cRnTzgQPT WAIvsnfcgNH75P/TnHkqZgJdtwBcJB1qKF2bAf7Ch+t1Kaqaqq37cz0iiIFucEh+C9eLDUhU2oVMC HKkejuk7JZn0riUxL6DwIxtoyi9Lfasp2Jb7Ci7GdZGSUtmyvErvPcLeX3LpsOSSr0uS5o6bS2pgz LB8ap+2A==; Original-Received: from 84-106-134-200.cable.dynamic.v4.ziggo.nl ([84.106.134.200] helo=[192.168.178.21]) by smtp7.tb.mail.iss.as9143.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jZ7kI-000837-7V for ntg-context@ntg.nl; Thu, 14 May 2020 08:53:30 +0200 In-Reply-To: X-Mailer: Apple Mail (2.3445.104.14) X-SourceIP: 84.106.134.200 X-Authenticated-Sender: havdmeer@ziggo.nl (via SMTP) X-Ziggo-spambar: / X-Ziggo-spamscore: 0.0 X-Ziggo-spamreport: CMAE Analysis: v=2.3 cv=Ne99K1L4 c=1 sm=1 tr=0 a=wCstmS+ZHA3zSJXjQC+ubA==:17 a=9+rZDBEiDlHhcck0kWbJtElFXBc=:19 a=sTwFKg_x9MkA:10 a=MiNTnEJAAAAA:8 a=YEMqx4UAAAAA:8 a=ACQCx6kCAAAA:8 a=xtERp6CFAAAA:8 a=a3nu-2BBAAAA:8 a=uVBSUMgFvtjmmgv0Y8sA:9 a=CjuIK1q_8ugA:10 a=I5G9wmsKekHo-p816tIA:9 a=dc6jhSZmRYKJz2jt:21 a=_W_S_7VecoQA:10 a=h_yiODzSPc_8bA1QPpgA:9 a=m-Z_27IZkzAA:10 a=fv9oaMEWgTs4BAR8N8QA:9 a=RPLA2_WgmZJeInGA:21 a=LmrbSfiT3hecnSZifb5M:22 a=V0662LiR8DSfwiDagK97:22 a=Sab0UneHBzlWrQDlOuxD:22 a=ekCXXmE-vB8RPiJ3MEZb:22 X-Ziggo-Spam-Status: No X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.io gmane.comp.tex.context:107307 Archived-At: --===============2884898573543692164== Content-Type: multipart/alternative; boundary="Apple-Mail=_DA4FB736-DDC0-4AAB-B883-A5EB2F8AB1B8" --Apple-Mail=_DA4FB736-DDC0-4AAB-B883-A5EB2F8AB1B8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Gerben, Maybe this is of some use. The Lua code in the file checks the xml and = returns info when something is wrong. I am using it for example in my takenotes module as: And this is a sketch of how it is embedded in that module: % Prerun an xml check. \doifinset{\xmlatt{#1}{checkxml}}{yes,on,true}% {\xmlcommand{#1}{.}{xmlcommon:checkxml}} % Execute this code if no error was found. etc. dr. Hans van der Meer > On 13 May 2020, at 23:00, Gerben Wierda wrote: >=20 > I am loading an xml.file. I sometimes make mistakes editing that file = and then xml.load creates a string that contains >=20 > invalid xml file - parsed text >=20 > At that point I check my file and sometimes (like now) I cannot find = the error. >=20 > Is there a way to make xml.load somewhat more verbose about where it = encounters the error?=20 >=20 > G > = __________________________________________________________________________= _________ > If your question is of interest to others as well, please add an entry = to the Wiki! >=20 > maillist : ntg-context@ntg.nl / = http://www.ntg.nl/mailman/listinfo/ntg-context > webpage : http://www.pragma-ade.nl / http://context.aanhet.net > archive : https://bitbucket.org/phg/context-mirror/commits/ > wiki : http://contextgarden.net > = __________________________________________________________________________= _________ --Apple-Mail=_DA4FB736-DDC0-4AAB-B883-A5EB2F8AB1B8 Content-Type: multipart/mixed; boundary="Apple-Mail=_E7EDA75A-014F-4728-9B27-0FA86601304E" --Apple-Mail=_E7EDA75A-014F-4728-9B27-0FA86601304E Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Gerben,

Maybe this is of some use. The Lua code in the file checks = the xml and returns info when something is wrong.
I am using it for example in my = takenotes module as:
<notes = file=3D"events/na-30416155-5-48v.xml" = checkxml=3D"yes"/>

And this is a sketch of how it is embedded in that = module:

% Prerun an xml check.
= \doifinset{\xmlatt{#1}{checkxml}}{yes,on,true}%
= {\xmlcommand{#1}{.}{xmlcommon:checkxml}}

% = Execute this code if no error was found.
etc.

dr. Hans van der Meer

= --Apple-Mail=_E7EDA75A-014F-4728-9B27-0FA86601304E Content-Disposition: attachment; filename=checkxml.txt Content-Type: text/plain; x-unix-mode=0644; name="checkxml.txt" Content-Transfer-Encoding: 7bit \startluacode -- Define our namespace as hvdm hvdm = hvdm or {} -- Function checks the correctness of an XML tree. hvdm.checkXMLtree = function (xml, linesep) local xml = xml and xml or "" local linesep = linesep and linesep or "\n" local badspace = {} -- Empty files do not need processing. if xml == "" then return "" end -- Step one is remove leading characters before first node. local leadingnode = string.find(xml, "<", 1) or 1 if leadingnode ~= 1 then xml = string.sub(xml, leadingnode, -1) end -- Strip all comments but node pairs inside make it complicated. local c1, c2 = string.find(xml, "", c2 + 1, true) if c3 then -- Remove comment. xml = string.sub(xml, 1, c1 - 1) .. string.sub(xml, c4 + 1, -1) -- Search for next comment. c1, c2 = string.find(xml, "