Reputation: 15091
I know how to write XML and XSD files but this is the first time I've actually used them in development. What is the point of the attribute schemaLocation (e.g. <note xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3schools.com note.xsd">
) because it can't be used to load an XSD file the XML file is supposed to adhere to?
Here is my situation. The project requirements are to have an input XML configuration file, and to have an XSD file for it. When the program is run, it first validates the XML against the XSD schema. My question is, how is the program made aware of the XSD file? Is it passed by a command line argument, obtained through parsing the string of schemaLocation
or can it be hard coded into the program as the schema for the input file will never change (or at least it's name wouldn't change)?
What's the "common practice" for validating an xml config file for a program?
Upvotes: 0
Views: 84
Reputation: 111726
What is the point of the attribute
schemaLocation
The xsd:schema/@schemaLocation
attribute provides a hint as to the location of the XSD to use for this XML document.
because it can't be used to load an XSD file the XML file is supposed to adhere to?
Yes, it really can be used to locate and load the XSD file that the XML is supposed to adhere to.
My question is, how is the program made aware of the XSD file?
The most common way is to use schemaLocation
for namespaced XML and noNamespaceSchemaLocation
for XML without namespaces. Conformant XML parsers typically by default will use these attributes to locate an XSD.
Is it passed by a command line argument, obtained through parsing the string of schemaLocation or can it be hard coded into the program as the schema for the input file will never change (or at least it's name wouldn't change)?
All of these options are possible, but as mentioned above, schemaLocation
and noNamespaceSchemaLocation
are most common.
Upvotes: 1