Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't find unclosed element in XML

Tags:

xml

I have a large XML file (~18MB). Apparently there is a tag somewhere in it that isn't closed. I know this because when I ran the W3C markup validation tool (validator.w3.org), I get the following error:

You may have neglected to close an element, or perhaps you meant to "self-close" an element, that is, ending it with "/>" instead of ">".

My question is how I might go about finding this missing closed element among the 500,000 lines in the file. Is there a tool I could use that would suggest places where there might be a problem -- such as an element that has not been closed after a certain number of lines?

Any ideas would be much appreciated.

like image 575
itzy Avatar asked Apr 03 '11 23:04

itzy


3 Answers

I use Notepad++ which has an excellent XML Tools plugin that lets you check XML Syntax and takes you to the line that is problematic. It also has useful utilities.

enter image description here

like image 165
Bala R Avatar answered Sep 28 '22 07:09

Bala R


I just opened an XML file in VS 2010 (with ReSharper), broke the XML and what do you know? The error was highlighted immediately. If you have access to the same, it's that simple.

like image 31
Jon Avatar answered Sep 28 '22 08:09

Jon


xmllint is a standard tool for this. From the Validation & DTDs page:

The simplest way is to use the xmllint program included with libxml. The --valid option turns-on validation of the files given as input. For example the following validates a copy of the first revision of the XML 1.0 specification:

xmllint --valid --noout test/valid/REC-xml-19980210.xml

the -- noout is used to disable output of the resulting tree.

The --dtdvalid dtd allows validation of the document(s) against a given DTD.

Libxml2 exports an API to handle DTDs and validation, check the associated description.

If your document isn't "pretty-printed" it can still be hard to find the offending node, so you might want to use xmllint to rewrite the file to be indented.

like image 23
the Tin Man Avatar answered Sep 28 '22 07:09

the Tin Man