Validating xml file against xsd
Source xml File = new Stream Source(new File("web.xml")); Schema Factory schema Factory = Schema Factory Instance(XMLConstants.
URL schema File = new URL(" // webapp example xsd: // URL schema File = new URL(" // local file example: // File schema File = new File("/location/to/localfile.xsd"); // etc.
I then downloaded Oxygen XML editor and it worked fine on the same XML and XSD files, so the files seem to be fine (or Oxygen is more forgiving / flexible . To define the namespace: In the XML file's root element: I had this same problem, but VS was referencing my schema correctly already.
I ended up using Liquid XML Studio 2008 (v6) which was much easier to use and more immediately familiar (the UI is very similar to Visual Basic 2008 Express, which I use frequently).Alternatively if you use Stax for writing content (or a library that uses or can use stax), Woodstox can also directly support validation when using XMLStream Writer.Here's a blog entry showing how that is done: If you are generating XML files programatically, you may want to look at the XMLBeans library.Using a command line tool, XMLBeans will automatically generate and package up a set of Java objects based on an XSD.You can then use these objects to build an XML document based on this schema.