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


Tags
validate xml using unix

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
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

Hi,

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


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

Sponsored Links
    #2  
Old 01-09-2013
fpmurphy's Avatar
fpmurphy fpmurphy is offline Forum Staff  
who?
 
Join Date: Dec 2003
Last Activity: 28 August 2014, 4:55 AM EDT
Location: /dev/ph
Posts: 4,786
Thanks: 63
Thanked 424 Times in 393 Posts
Assuming your XML document is called output.xml, here is what xmllint outputs:

Code:
xmllint output.xml
output.xml:16: parser error : Opening and ending tag mismatch: UnitList line 15 and ProductInformation
</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 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 06:13 AM.