user1390517
user1390517

Reputation: 249

How to validate an xml file in ant?

this is my xml file <contacts> <contact> <firstname>Edwin</firstname> <lastname>Dankert</lastname> </contact> </contacts>

i want to validate it in ant,my target is

<target name="WellFormed">
<xmlvalidate file="contacts.xml"/>
<echo>WELL FORMED</echo>
</target>

C:\work\build\XML_VALIDATION>ant Buildfile: C:\work\build\XML_VALIDATION\build.xml

<==========================ANT OUTPUT=============================>

WellFormed:
[xmlvalidate] contacts.xml:1:11: Document root element "contacts", must match DOCTYPE root "null".

[xmlvalidate] contacts.xml:1:11: Document is invalid: no grammar found.

BUILD FAILED
C:\work\build\XML_VALIDATION\build.xml:4: C:\work\build\XML_VALIDATION\contacts.xml is not a valid XML document.

i am not checking it against any xsd,can anyone help me in finding what changes i need to insert into the xml.

Upvotes: 1

Views: 2583

Answers (2)

Kasun Gajasinghe
Kasun Gajasinghe

Reputation: 2776

If you just want to make sure your XML is well-formed, then add the lenient attribute to your xmlvalidate task as follows.

<xmlvalidate file="contacts.xml" lenient="yes"/>

Upvotes: 2

omermuhammed
omermuhammed

Reputation: 7385

Your build file is not valid, you need to start with

<?xml version="1.0"?>
<project name="name">
<target name="target-name">
...
</target>
</project>

A google search for sample Ant build file will provide all you need to understand build files. This link will help too.

Upvotes: 0

Related Questions