Xml tidy doesn't work anymore in v4

2,430 views
Skip to first unread message

Epharion

unread,
May 7, 2012, 9:15:16 AM5/7/12
to TextWrangler Talk
Hi,

I have this script :

#!/bin/sh
xmllint --c14n "$*" | XMLLINT_INDENT=$'\t' xmllint --encode UTF-8 --
format -


In V3, it works very good but since V4 I got this :

warning: failed to load external entity ""
-:1: parser error : Document is empty

^
-:1: parser error : Start tag expected, '<' not found

^


Someone can help ?

Thanks a lot (sorry for my bad english)

Patrick Woolsey

unread,
May 7, 2012, 10:51:05 AM5/7/12
to textwr...@googlegroups.com
Epharion <epha...@gmail.com> sez:

>I have this script :
>
>#!/bin/sh
>xmllint --c14n "$*" | XMLLINT_INDENT=$'\t' xmllint --encode UTF-8 -- format -
>
>
>In V3, it works very good but since V4 I got this :
>
>warning: failed to load external entity ""
>-:1: parser error : Document is empty


TextWrangler 4 now passes either the selected text (if any) or the contents
of the entire document directly to text filters on STDIN, instead of
passing a reference to a temporary file in argv[1].


Thus, you'll need to change the first 'xmllint' command to take input from
STDIN, like so:

====
#!/bin/sh
xmllint --c14n - | XMLLINT_INDENT=$'\t' xmllint --encode UTF-8 --format -
====


Regards,

Patrick Woolsey
==
Bare Bones Software, Inc. <http://www.barebones.com>
P.O. Box 1048, Bedford, MA 01730-1048

Thomas Fischer

unread,
May 7, 2012, 11:39:32 AM5/7/12
to textwr...@googlegroups.com
Hi Epharion,

I had the same problem, it has to do with the change in communication between TextWrangler and Unix.
I changed my script to

#!/bin/sh

XMLLINT_INDENT=$'\t' xmllint --format --encode utf-8 -

and that works – the dash at the end picks up the text.

Best
Thomas
> --
> You received this message because you are subscribed to the
> "TextWrangler Talk" discussion group on Google Groups.
> To post to this group, send email to textwr...@googlegroups.com
> To unsubscribe from this group, send email to
> textwrangler...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/textwrangler?hl=en
> If you have a feature request or would like to report a problem,
> please email "sup...@barebones.com" rather than posting to the group.

Mirco

unread,
May 8, 2012, 5:01:17 AM5/8/12
to textwr...@googlegroups.com
Does anyone know hot to get a perl script back working?

I tried IMHO all possibilities, but:

#!/usr/bin/perl -w 
print <STDIN>, <>, $ARGV[0]; 

Doesn't output anything. It even doesn't matter, if there's a text selection or not.

Thomas Fischer

unread,
May 8, 2012, 3:56:15 PM5/8/12
to textwr...@googlegroups.com
Hi,

for me, constructions like

#!/usr/bin/perl

my @text = <STDIN>;
$_ = join "",@text; # Slurp für TextWrangler


or

while (<STDIN>) {
}

work as expected; I had to change those scripts but don't know what I had before,

Best
Thomas


wivaku

unread,
May 9, 2012, 1:28:44 PM5/9/12
to textwr...@googlegroups.com
Hi Patrick,
I tried this with a sample file and got errors:

---
/dev/stdin:1: parser error : Document is empty
/dev/stdin:1: parser error : Start tag expected, '<' not found
-:1: parser error : Document is empty
-:1: parser error : Start tag expected, '<' not found
---

I used the script from your reply:
---
#!/bin/sh 
xmllint --c14n - | XMLLINT_INDENT=$'\t' xmllint --encode UTF-8 --format - 
---

I stored it as "Tidy XML.sh" in ~/Library/Application Support/TextWrangler/Scripts

When I store the XML text in a file and run it from the command line, then the output is as expected:
---
cat /var/tmp/testfile.xml | xmllint --c14n - | XMLLINT_INDENT=$'\t' xmllint --encode UTF-8 --format - 
---

Suggestions?
Using TextWrangler 4.0 (3142) [and love it!]

Thomas Fischer

unread,
May 9, 2012, 3:39:28 PM5/9/12
to textwr...@googlegroups.com
Hello,

for me the script works fine.
Is it possible that you have some text selected before calling the script? This usually won't work because xmllint needs a valid XML file to act upon.

Best
Thomas

wivaku

unread,
May 9, 2012, 4:01:11 PM5/9/12
to textwr...@googlegroups.com
Hi Thomas,
Good point about the selected text.
I forgot to mention I tried running the script from TextWrangler with no and with all text selected.
Same result. :-(
Also tried the most simple script:
---
#!/bin/sh  
wc
---

The output (with and without selected text):
       0       0       0

Patrick Woolsey

unread,
May 9, 2012, 4:11:34 PM5/9/12
to textwr...@googlegroups.com
wivaku <wiv...@gmail.com> sez:

> I tried this with a sample file and got errors:
>
[ ... details elided ... ]
>
> I used the script from your reply:
> [and] stored it as "Tidy XML.sh" in ~/Library/Application
> Support/TextWrangler/Scripts


Those errors occurred because you ran the script directly instead of
applying it to the current document.

TextWrangler supports using such items as either[1]:

* Text filters, which process the contents of the current document, or

* Scripts, which are programs that run independently.

Thus, in order to use this file as a text filter, you must move it to:

~/Library/Application Support/TextWrangler/Text Filters/

and apply it via Text -> Apply Text Filter -> [filter name e.g. "Tidy XML"]


[1. For complete details, please see the section "Filters and Scripts"
in TextWrangler's PDF manual (choose Help -> User Manual).]


I hope this helps, and think it should cover everything. :)

wivaku

unread,
May 9, 2012, 4:16:08 PM5/9/12
to textwr...@googlegroups.com
Argh, that's it! How silly of me.
All is working fine now.
Thanks for the great product and the fast response!


On Wednesday, May 9, 2012 10:11:34 PM UTC+2, Patrick Woolsey wrote:

Michael Bierman

unread,
May 13, 2012, 1:13:00 AM5/13/12
to textwr...@googlegroups.com
I'm having a bit of trouble. 

I have the script

#!/bin/sh 
xmllint --c14n - | XMLLINT_INDENT=$'\t' xmllint --encode UTF-8 --format - 


saved in 

~/Library/Application Support/TextWrangler/Text Filters/Tidy XML.sh

I put the cursor at the very beginning of an XML file, no text selected. I run the text filter and I get:

    (application error code: 32)

Any thoughts on what I might be doing wrong? 



On Wednesday, May 9, 2012 1:11:34 PM UTC-7, Patrick Woolsey wrote:
wivaku  sez:

Michael Bierman

unread,
May 13, 2012, 1:17:24 AM5/13/12
to textwr...@googlegroups.com
I'm having a bit of trouble. 

I have the script

#!/bin/sh 
xmllint --c14n - | XMLLINT_INDENT=$'\t' xmllint --encode UTF-8 --format - 


saved in 

~/Library/Application Support/TextWrangler/Text Filters/Tidy XML.sh

I put the cursor at the very beginning of an XML file, no text selected. I run the text filter and I get:

    (application error code: 32)

Any thoughts on what I might be doing wrong? 



On Wednesday, May 9, 2012 1:11:34 PM UTC-7, Patrick Woolsey wrote:
wivaku  sez:

Thomas Fischer

unread,
May 13, 2012, 1:05:25 PM5/13/12
to textwr...@googlegroups.com
Hello Michael,

I can't  reciprocate you error, the script I copied from your email works fine with me.
But I can generate the (application error code: 32) error if I change some of the dashes to similar but different characters like n-dash or m-dash. E.g.

#!/bin/sh
xmllint --c14n – | XMLLINT_INDENT=$'\t' xmllint --encode UTF-8 --format -

will generate such an error, here the dash in c14n – | XMLLINT is Unicode 8211 (\x{2013}).

Best
Thomas

Michael Bierman

unread,
May 13, 2012, 1:25:57 PM5/13/12
to textwr...@googlegroups.com
Actually I think I may have found the problem. I created the shell script in TextWrangler. When I looked at it in vi, I saw a funny character ^M I think? at the end of the #! line. Fixing that solved the problem.  Might be something to add to the scripting FAQ. 

Thank you very much.


Michael Bierman




Thomas Fischer

unread,
May 14, 2012, 3:45:13 AM5/14/12
to textwr...@googlegroups.com
Hello Michael,


Actually I think I may have found the problem. I created the shell script in TextWrangler. When I looked at it in vi, I saw a funny character ^M I think? at the end of the #! line. Fixing that solved the problem.  Might be something to add to the scripting FAQ. 

I suppose that using
View -> Text Display -> Show Invisibles
in TextWrangler would have displayed that character as well.
I use a small AppleScript to check what the " ¿" actually means.

Best
Thomas
Reply all
Reply to author
Forward
0 new messages