I have a XML file and a a bunch of XSD files with schemas. How do I parse the XML file using the correct XSD file and schema in PHP?
Reference the XSD schema in the XML document using XML schema instance attributes such as either xsi:schemaLocation or xsi:noNamespaceSchemaLocation. Add the XSD schema file to a schema cache and then connect that cache to the DOM document or SAX reader, prior to loading or parsing the XML document.
Basically an XSD file defines how the XML file is going to look like. It's a Schema file which defines the structure of the XML file. So it specifies what the possible fields are and what size they are going to be. An XML file is an instance of XSD as it uses the rules defined in the XSD.
To create an XML file from an XSD file: Right-click the XML Documents folder in your data development project, and select New > XML. The New XML File wizard opens.
XsdParser is a library that parses a XML Definition file (. xsd) into a list of java objects. Each different XSD tag has a corresponding Java class and the attributes of a given XSD type are represented as fields of that class.
You can use the DOM or XmlReader extensions
DOMDocument::schemaValidate
— Validates a document based on a schema XMLReader::setSchema
— Validate document against XSDto validate documents against a schema.
Check this tool - http://github.com/moyarada/XSD-to-PHP. It sounds exactly what you're asking. You can marshal/unmarshal XML usind generated from XSD PHP classes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With