Is there any gradle plugin to validate XML?
up vote
0
down vote
favorite
I work on a project where we have xml files for code generation and we use gradle
to build it.
I'm novice in gradle
, but I heard that there are a lot of plugins
that could help with routine tasks and I wonder if there are some plugins for xml simple validation (missing quotes and brackets).
I would like to get name of file and list of missings as result.
PS Tried to search in google, but couldn't find something like that.
UPD If in not so distant future full validation of xml file (tags, parameters) would be required, what should I do?
xml validation gradle automation gradle-plugin
add a comment |
up vote
0
down vote
favorite
I work on a project where we have xml files for code generation and we use gradle
to build it.
I'm novice in gradle
, but I heard that there are a lot of plugins
that could help with routine tasks and I wonder if there are some plugins for xml simple validation (missing quotes and brackets).
I would like to get name of file and list of missings as result.
PS Tried to search in google, but couldn't find something like that.
UPD If in not so distant future full validation of xml file (tags, parameters) would be required, what should I do?
xml validation gradle automation gradle-plugin
The term "validation" in the XML world has a specialized meaning: it means checking that the XML conforms with some supplied schema. A schema might say that ap
element can containi
elements but not vice versa. I suspect this isn't what you are looking for: the phrase "missing quotes and brackets" suggests you just want to check if a file contains well-formed XML.
– Michael Kay
Nov 10 at 11:26
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I work on a project where we have xml files for code generation and we use gradle
to build it.
I'm novice in gradle
, but I heard that there are a lot of plugins
that could help with routine tasks and I wonder if there are some plugins for xml simple validation (missing quotes and brackets).
I would like to get name of file and list of missings as result.
PS Tried to search in google, but couldn't find something like that.
UPD If in not so distant future full validation of xml file (tags, parameters) would be required, what should I do?
xml validation gradle automation gradle-plugin
I work on a project where we have xml files for code generation and we use gradle
to build it.
I'm novice in gradle
, but I heard that there are a lot of plugins
that could help with routine tasks and I wonder if there are some plugins for xml simple validation (missing quotes and brackets).
I would like to get name of file and list of missings as result.
PS Tried to search in google, but couldn't find something like that.
UPD If in not so distant future full validation of xml file (tags, parameters) would be required, what should I do?
xml validation gradle automation gradle-plugin
xml validation gradle automation gradle-plugin
edited Nov 9 at 20:08
asked Nov 9 at 18:02
Denis Sablukov
550519
550519
The term "validation" in the XML world has a specialized meaning: it means checking that the XML conforms with some supplied schema. A schema might say that ap
element can containi
elements but not vice versa. I suspect this isn't what you are looking for: the phrase "missing quotes and brackets" suggests you just want to check if a file contains well-formed XML.
– Michael Kay
Nov 10 at 11:26
add a comment |
The term "validation" in the XML world has a specialized meaning: it means checking that the XML conforms with some supplied schema. A schema might say that ap
element can containi
elements but not vice versa. I suspect this isn't what you are looking for: the phrase "missing quotes and brackets" suggests you just want to check if a file contains well-formed XML.
– Michael Kay
Nov 10 at 11:26
The term "validation" in the XML world has a specialized meaning: it means checking that the XML conforms with some supplied schema. A schema might say that a
p
element can contain i
elements but not vice versa. I suspect this isn't what you are looking for: the phrase "missing quotes and brackets" suggests you just want to check if a file contains well-formed XML.– Michael Kay
Nov 10 at 11:26
The term "validation" in the XML world has a specialized meaning: it means checking that the XML conforms with some supplied schema. A schema might say that a
p
element can contain i
elements but not vice versa. I suspect this isn't what you are looking for: the phrase "missing quotes and brackets" suggests you just want to check if a file contains well-formed XML.– Michael Kay
Nov 10 at 11:26
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
It's pretty simple to write your own
class XmlValidate extends DefaultTask
@InputFiles
private FileCollection xmlFiles
@InputFile
File xsd
void xml(Object files)
FileCollection fc = project.files(files)
this.xmlFiles = this.xmlFiles == null ? fc : this.xmlFiles.add(fc)
@TaskAction
public void validateXml()
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder()
Validator validator = null
if (xsd != null)
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
Schema schema = factory.newSchema(new StreamSource(xsd))
validator = schema.newValidator()
Set<File> failures = as Set
xmlFiles.forEach
Document document = null
try
document = parser.parse(it)
catch (Exception e)
logger.error("Error parsing $it", e)
failures << it
if (document && validator)
try
validator.validate(new DOMSource(document))
catch (Exception e)
logger.error("Error validating $it", e)
failures << it
if (failures) throw new BuildException("xml validation failures $failures")
Usage in build.gradle
task validateXml(type: XmlValidate)
xml ['foo.xml', 'bar.xml']
xml fileTree(dir: 'src/main/resources/baz', include: '*.xml')
xsd = file('path/to.xsd')
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
It's pretty simple to write your own
class XmlValidate extends DefaultTask
@InputFiles
private FileCollection xmlFiles
@InputFile
File xsd
void xml(Object files)
FileCollection fc = project.files(files)
this.xmlFiles = this.xmlFiles == null ? fc : this.xmlFiles.add(fc)
@TaskAction
public void validateXml()
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder()
Validator validator = null
if (xsd != null)
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
Schema schema = factory.newSchema(new StreamSource(xsd))
validator = schema.newValidator()
Set<File> failures = as Set
xmlFiles.forEach
Document document = null
try
document = parser.parse(it)
catch (Exception e)
logger.error("Error parsing $it", e)
failures << it
if (document && validator)
try
validator.validate(new DOMSource(document))
catch (Exception e)
logger.error("Error validating $it", e)
failures << it
if (failures) throw new BuildException("xml validation failures $failures")
Usage in build.gradle
task validateXml(type: XmlValidate)
xml ['foo.xml', 'bar.xml']
xml fileTree(dir: 'src/main/resources/baz', include: '*.xml')
xsd = file('path/to.xsd')
add a comment |
up vote
1
down vote
accepted
It's pretty simple to write your own
class XmlValidate extends DefaultTask
@InputFiles
private FileCollection xmlFiles
@InputFile
File xsd
void xml(Object files)
FileCollection fc = project.files(files)
this.xmlFiles = this.xmlFiles == null ? fc : this.xmlFiles.add(fc)
@TaskAction
public void validateXml()
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder()
Validator validator = null
if (xsd != null)
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
Schema schema = factory.newSchema(new StreamSource(xsd))
validator = schema.newValidator()
Set<File> failures = as Set
xmlFiles.forEach
Document document = null
try
document = parser.parse(it)
catch (Exception e)
logger.error("Error parsing $it", e)
failures << it
if (document && validator)
try
validator.validate(new DOMSource(document))
catch (Exception e)
logger.error("Error validating $it", e)
failures << it
if (failures) throw new BuildException("xml validation failures $failures")
Usage in build.gradle
task validateXml(type: XmlValidate)
xml ['foo.xml', 'bar.xml']
xml fileTree(dir: 'src/main/resources/baz', include: '*.xml')
xsd = file('path/to.xsd')
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
It's pretty simple to write your own
class XmlValidate extends DefaultTask
@InputFiles
private FileCollection xmlFiles
@InputFile
File xsd
void xml(Object files)
FileCollection fc = project.files(files)
this.xmlFiles = this.xmlFiles == null ? fc : this.xmlFiles.add(fc)
@TaskAction
public void validateXml()
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder()
Validator validator = null
if (xsd != null)
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
Schema schema = factory.newSchema(new StreamSource(xsd))
validator = schema.newValidator()
Set<File> failures = as Set
xmlFiles.forEach
Document document = null
try
document = parser.parse(it)
catch (Exception e)
logger.error("Error parsing $it", e)
failures << it
if (document && validator)
try
validator.validate(new DOMSource(document))
catch (Exception e)
logger.error("Error validating $it", e)
failures << it
if (failures) throw new BuildException("xml validation failures $failures")
Usage in build.gradle
task validateXml(type: XmlValidate)
xml ['foo.xml', 'bar.xml']
xml fileTree(dir: 'src/main/resources/baz', include: '*.xml')
xsd = file('path/to.xsd')
It's pretty simple to write your own
class XmlValidate extends DefaultTask
@InputFiles
private FileCollection xmlFiles
@InputFile
File xsd
void xml(Object files)
FileCollection fc = project.files(files)
this.xmlFiles = this.xmlFiles == null ? fc : this.xmlFiles.add(fc)
@TaskAction
public void validateXml()
DocumentBuilder parser = DocumentBuilderFactory.newInstance().newDocumentBuilder()
Validator validator = null
if (xsd != null)
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI)
Schema schema = factory.newSchema(new StreamSource(xsd))
validator = schema.newValidator()
Set<File> failures = as Set
xmlFiles.forEach
Document document = null
try
document = parser.parse(it)
catch (Exception e)
logger.error("Error parsing $it", e)
failures << it
if (document && validator)
try
validator.validate(new DOMSource(document))
catch (Exception e)
logger.error("Error validating $it", e)
failures << it
if (failures) throw new BuildException("xml validation failures $failures")
Usage in build.gradle
task validateXml(type: XmlValidate)
xml ['foo.xml', 'bar.xml']
xml fileTree(dir: 'src/main/resources/baz', include: '*.xml')
xsd = file('path/to.xsd')
edited Nov 10 at 13:23
answered Nov 10 at 12:14
lance-java
15.9k12858
15.9k12858
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231114%2fis-there-any-gradle-plugin-to-validate-xml%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The term "validation" in the XML world has a specialized meaning: it means checking that the XML conforms with some supplied schema. A schema might say that a
p
element can containi
elements but not vice versa. I suspect this isn't what you are looking for: the phrase "missing quotes and brackets" suggests you just want to check if a file contains well-formed XML.– Michael Kay
Nov 10 at 11:26