XML validation | Unix Linux Forums | UNIX for Dummies Questions & Answers

  Go Back    

UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

XML validation

UNIX for Dummies Questions & Answers

validate xml using unix

Closed Thread    
Thread Tools Search this Thread Display Modes
Old 01-09-2013
siri_886 siri_886 is offline
Registered User
Join Date: Jul 2009
Last Activity: 9 January 2013, 2:20 PM EST
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
XML validation


I have a requirement where I need to validate the xmls that are getting generated by an application if it is well formed or not.

If it has generated incomplete xml (such as missing tags), then I need to correct it using some UNIX commands and have to process it.

I even gone through xmllint tool, but I could not understand how and what exactly it works and also could not understand how to use it.

Could anyone please help on this?

My XML look like below

<?xml version="1.0" encoding="utf-8"?>
<ProductInformation WorkspaceID="afjeqoe">
    <Qualifier ID="1">
      <DimensionPointLink DimensionPointID="eng"/>
    <Qualifier ID="2">
      <DimensionPointLink DimensionPointID="std.lang.all"/>
    <Qualifier ID="3">
      <DimensionPointLink DimensionPointID="USMarket"/>
    <Qualifier ID="Qualifier root"/>

Sponsored Links
Old 01-10-2013
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
Join Date: Dec 2003
Last Activity: 26 January 2015, 5:33 PM EST
Location: /dev/ph
Posts: 4,859
Thanks: 66
Thanked 439 Times in 407 Posts
Assuming your XML document is called output.xml, here is what xmllint outputs:

xmllint output.xml
output.xml:16: parser error : Opening and ending tag mismatch: UnitList line 15 and ProductInformation
output.xml:17: parser error : Premature end of data in tag ProductInformation line 2


It clearly shows that the error is on line 15 and is due to the UnitList element not having a matching opening and closing tag. This is correct.

As to fixing XML documents that are not well formed, in the general case that is not possible due to too many variables. However if you have a good XML Schema, it is possible.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
XML: parsing of the Google contacts XML file ripat Shell Programming and Scripting 9 12-25-2012 11:07 AM
How to add the multiple lines of xml tags before a particular xml tag in a file mjavalkar Shell Programming and Scripting 0 06-25-2012 05:54 PM
XML file validation bmk Shell Programming and Scripting 2 02-09-2012 08:05 AM
How to remove xml namespace from xml file using shell script? Gary1978 Shell Programming and Scripting 10 10-26-2008 10:32 PM

All times are GMT -4. The time now is 09:03 PM.