• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help in testing xml

 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I want to test my knowledge with xml and xsd. Do i have to use javacode to validate my xml against xsd or there is anyother way?
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
No you do not have to use Java - both Eclipse and NetBeans contain XML editors which can validate an XML document against its schema.
If you want to be more exclusive, there are special XML editors, like Oxygen XML (http://www.oxygenxml.com/), that also can validate XML documents against XML schemas.
Best wishes!
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is there a way to validate xml using xsd in eclipse? i was able to create xsd from editor but i am not able to validate. any help is appreciated.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
nitin pokhriyal wrote:is there a way to validate xml using xsd in eclipse? i was able to create xsd from editor but i am not able to validate. any help is appreciated.

Have you tried right-clicking in the editor window of the XSD file and selecting validate?
Best wishes!
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank Ivan for your help, I can validate xsd but problem is that i am not able to validate my xml data against the xsd. I will try again may be i am not using correct format. I will post my example, i think that will easy for other to reply
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is my xsd
<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.ibm.com" xmlns="http://www.ibm.com">
<xsd:complexType name="AddressType">
<xsd:sequence>
<xsd:element name="name" type="xsd:string"></xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:element name="MyAddress" type="AddressType"></xsd:element>
</xsd:schema>

and here is my xml
<?xml version="1.0"?>
<x:MyAddress xmlns:x="http://www.ibm.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ibm.com/NewXMLSchema.xsd ">
<aname>Peter Smith</aname>
</x:MyAddress>

so this xml is wrong but how do i validate xml against above mentioned xsd in eclipse.
In eclipse i just got warning but if i don't close tags or start/end tag does not match then i got error. I want to validate if the tags are missing or may be tag not at all defined in xsd as i am trying "aname" tag but in xsd "name" is defined.

Thanks
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
If you want the validator to be able to find the XML schema, you must specify its location in the value of the schemaLocation attribute.
If the schema is located in the same directory as the XML file, then the specification of the schema location would look something like this:

Hint: Look at row 3!
Hope this helps!
 
nitin pokhriyal
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
IVAN thank you very much, It worked now.


Here is xml which validated successfully. if i change any tag it gives validation error(Though it was not understable).

<?xml version="1.0"?>
<x:MyAddress xmlns:x="http://www.ibm.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.ibm.com NewXMLSchema.xsd ">
<name>Peter Smith</name>
</x:MyAddress>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic