Unix/Linux Go Back    

UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

XML validation

UNIX for Dummies Questions & Answers

validate xml using unix

Thread Tools Search this Thread Display Modes
Old Unix and Linux 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 Unix and Linux 01-09-2013
fpmurphy's Unix or Linux Image
fpmurphy fpmurphy is offline
Registered User
Join Date: Dec 2003
Last Activity: 12 June 2016, 11:03 PM EDT
Location: /dev/ph
Posts: 4,996
Thanks: 73
Thanked 475 Times in 437 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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 10: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 04:54 PM
XML file validation bmk Shell Programming and Scripting 2 02-09-2012 07:05 AM
How to remove xml namespace from xml file using shell script? Gary1978 Shell Programming and Scripting 10 10-26-2008 09:32 PM

All times are GMT -4. The time now is 01:44 PM.