I have some XML and an XML Schema in a local xsd file. The XML document does not contain any schema information. I want to validate the XML document against the xsd schema file in Cocoa (meaning I’d prefer something NS/CF/libxml based as opposed to an external library).
I can across xmllint, which would probably work, but I was looking for a way to do it without launching an external task.
If your xml document does not have a reference to the xml schema, you should add it yourself, then validate with NSXMLDocument
validateAndReturnError:method.Here is an example of how to tweak the xml document to have a reference to the xsd. Obviously, you will have to adapt this code to have a reference to your local xsd file.
For reference:
Contents of http://www.xmlschema.info/PO.xml
Contents of http://www.xmlschema.info/PO.xsd