XML Validation (.dtd or .xsd)

Justin Lee2
Tera Guru

We have a requirement to validate the XML in a particular xml field against a DTD file (.dtd).

Is there any way to do this in ServiceNow?  We could switch them to .xsd validation if there is an option for that, but .dtd would be preferred.

Thanks,

Justin

2 REPLIES 2

Community Alums
Not applicable

Hi @Justin Lee ,

This doc should help you :

https://docs.servicenow.com/en-US/bundle/sandiego-platform-administration/page/administer/security/r...

Mark my answer correct & Helpful, if Applicable.

Thanks,
Sandeep

Thanks Sundeep.  Can you (or anyone here) verify that XmlDocument2 validates against a specified .dtd file?  And if so, how do we get the result? (and resulting error message)  

We have glide.xml.entity.whitelist.enabled property set to true, and to test, I am using a .dtd file that is also whitelisted by default.  (http://java.sun.com/j2ee/dtds/application-client_1_2.dtd)

My test is validating the XML below, which should be considered invalid, because icon is specified multiple times, and the .dtd file does not allow that.

Both xmlDoc.parseXML() and xmlDoc.isValid() both return true.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application-client SYSTEM "http://java.sun.com/j2ee/dtds/application-client_1_2.dtd">
<application-client>
	<icon>Icon 1</icon>
	<icon>Icon 2</icon>
	<icon>Icon 3</icon>
	<icon>Icon 4</icon>
</application-client>