Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

eclipse: validate xml with xsd

does anyone know if it is possible to validate an xml with an xsd while i am editing the xml in eclipse?

this is how my xml begins:

<root      xmlns:xi="http://www.w3.org/2001/XInclude"     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"     xsi:noNamespaceSchemaLocation="../definitions.xsd"> 

alt text

like image 419
clamp Avatar asked Nov 16 '10 12:11

clamp


People also ask

How do you validate an XML file using Java with an XSD having an include?

newSchema(schemaFile); // create a Validator instance, which can be used to validate an instance document Validator validator = schema. newValidator(); // validate the DOM tree try { validator. validate(new StreamSource(new File("instance. xml")); } catch (SAXException e) { // instance document is invalid! }

How do I know if my XSD is valid?

All you have to do is just paste the XML and click on “Check XSD validity” button. In XML Schema Definition (XSD), we can verify: Checking the schema in its value. The same name field by checking its data type.

How do I validate in eclipse?

Select "Properties" -> Validation and make sure the validation properties page has following defaults selected. - Select the Override validation preferences check box to enable the preferences in this page. - Make sure "Select All" and "Deselect All" buttons check and uncheck all the validators.


2 Answers

Right click and Validate. If it is not validated, then Eclipse cannot reach the XSD file. Is definitions.xsd in the parent directory of the XML? You can also define XML catalog entries for your xsds. Anyway, if everything is fine, during saving it should validate XML. Validation usually come together with code completion of elements and attributes. They usually both work or neither.

UPDATE:

Picture to make validate action more clear: alt text

like image 140
Gábor Lipták Avatar answered Sep 25 '22 01:09

Gábor Lipták


I found out why the validate option doesn't show up. It happens when you browse files in your local filesystem. You should promote folder to a project, or just add xml and xsd files to some temporary project. Then validate as well as many other options should appear in contex menu.

I'm using eclipse 3.5.2 on Ubuntu.

like image 45
lukcio Avatar answered Sep 24 '22 01:09

lukcio