Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » How do you validate XML with Schema in Eclipse?(It seems Eclipse does not find the XSD file but gives no error)
How do you validate XML with Schema in Eclipse? [message #530254] Thu, 29 April 2010 06:46 Go to next message
wic is currently offline wic
Messages: 5
Registered: April 2010
Junior Member
I am trying to validate an XML file against it's XML Schema (*.xsd) in the Eclipse GUI , but I cannot get it to work.

When I right-click the xml-file and select "Validate", it gives me no validation error at all and says "Validation successful" (or something along those lines). So Eclipse does is not using the xsd-file at all Mad

For this example, I used the files here: http://www.w3schools.com/Schema/schema_example.asp

I created two files (shiporder.xml and shiporder.xsd) into a empty project in Eclipse and messed up some tags in the xml file.

I have tried all types of permutations with schema location attributes and even used the Preferences/XML/Schema catalog, but nothing seems to work.

Here is the XML:

<?xml version="1.0" encoding="UTF-8"?>
<shiporder orderid="" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:noNamespaceSchemaLocation="shiporder.xsd">
  <XXX_orderperson>orderperson</XXX_orderperson>
  <shipto>
    <name>name</name>
    <address>address</address>
    <city>city</city>
    <country>country</country>
  </shipto>
  <item>
    <title>title</title>
    <quantity>1</quantity>
    <price>0.0</price>
  </item>
</shiporder>

(Note the messed up tags just to (supposedly) trigger the validation error)

Here is the XSD:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<xs:schema xmlns:xs="[url]http://www.w3.org/2001/XMLSchema[/url]">
<xs:element name="shiporder">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="orderperson" type="xs:string"/>
      <xs:element name="shipto">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="name" type="xs:string"/>
            <xs:element name="address" type="xs:string"/>
            <xs:element name="city" type="xs:string"/>
            <xs:element name="country" type="xs:string"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="item" maxOccurs="unbounded">
        <xs:complexType>
          <xs:sequence>
            <xs:element name="title" type="xs:string"/>
            <xs:element name="note" type="xs:string" minOccurs="0"/>
            <xs:element name="quantity" type="xs:positiveInteger"/>
            <xs:element name="price" type="xs:decimal"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
    </xs:sequence>
    <xs:attribute name="orderid" type="xs:string" use="required"/>
  </xs:complexType>
</xs:element>
</xs:schema>


I would expect it to say "No definition for element XXX_xxxx" found or something like that. But no...

SUCCESS. Yeah right!

This is with Eclipse Build id: 20100218-1602
Re: How do you validate XML with Schema in Eclipse? [message #530320 is a reply to message #530254] Thu, 29 April 2010 11:13 Go to previous messageGo to next message
Sarika Sinha is currently offline Sarika Sinha
Messages: 47
Registered: February 2010
Location: Bangalore, India
Member
Hi,
I tried these on the latest build, for xsd it gave me error for [url]. I removed them and then when I tried validating the xml it said, xsd should have a target space. After adding the targetspace, I got the error in xml file you were looking for.

Try this in xsd :
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.w3.org/2001/XMLSchema">

And in xml:
<shiporder orderid="" xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/2001/XMLSchema shiporder.xsd">



Sarika Sinha
JDT Programmer
Re: How do you validate XML with Schema in Eclipse? [message #530325 is a reply to message #530320] Thu, 29 April 2010 11:45 Go to previous messageGo to next message
wic is currently offline wic
Messages: 5
Registered: April 2010
Junior Member
Well '[url]' is some crap inserted by this forum I guess. I'm not that retarded Wink ...

Anyway, I tried these files on my home Mac machine with Build id: 20090920-1017 (Galileo) and it worked 100% straight away there (after I fixed the XXX_string).

I got no message about needing at target space as you did.

To bad that it doesn't work at all at my work installation though.

/Thanks



Re: How do you validate XML with Schema in Eclipse? [message #530682 is a reply to message #530325] Fri, 30 April 2010 14:09 Go to previous messageGo to next message
David Carver is currently offline David Carver
Messages: 174
Registered: July 2009
Senior Member
Have you guys tried adding the necessary schemas to the XML Catalog within eclipse. XML Schemas are handled by namespace or via schemaLocation. Keep in mind that if you use schemaLocation you need to provide the path where the schema resides.

Also, make sure you have turned on in the Preferences for XML, "Warn when no grammar present" to notify you if it can find an appropriate grammar for the XML in question.

For more info on using the XML Catalogs see: http://wiki.eclipse.org/Using_the_XML_Catalog
Re: How do you validate XML with Schema in Eclipse? [message #531010 is a reply to message #530682] Mon, 03 May 2010 11:34 Go to previous message
wic is currently offline wic
Messages: 5
Registered: April 2010
Junior Member
Thanks, but still no success.

I have enabled schema grammar not present warning, but I get no feedback from Eclipse at all.
Previous Topic:No content assist for EL in JSP?
Next Topic:using WTP in Helios
Goto Forum:
  


Current Time: Mon Oct 20 11:32:38 GMT 2014

Powered by FUDForum. Page generated in 0.01980 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software