Skip to main content

Posts

Showing posts with the label parsing

DOM Parser Vs. SAX Parser

Many developers sometimes confuse which is better to parse the XML document. Ofcourse myself also got doubt which parser I can use for this situation.  Since I have read about DOM and SAX very long back. Just refreshing it again DOM (Document Object Model) Parser: Tree model parser(Object based) (Tree of nodes). DOM loads the file into the memory and then parse the file. Has memory constraints since it loads the whole XML file before parsing. DOM is read and write (can insert or delete the node). If the XML content is small then prefer DOM parser. Backward and forward search is possible for searching the tags and evaluation of the information inside the tags. So this gives the ease of navigation. Slower at run time.

Solution For Error: " Current configuration of the parser doesn't allow a maxOccurs attribute value to be set greater than the value 5,000."

Currently I am working on a project where I need to transform Excel sheet data to an XML format in compliance with XSD given by my client. When I am trying to parse the XSD using JAXB I got this error when doing mvn clean install. Error: ""Current configuration of the parser doesn't allow a maxOccurs attribute value to be set greater than the value 5,000." I found many solutions and route cause for this issue. You can find some information on Oracle site the route cause for the issue . It is because of the feature enabled for secure XML processing. This feature was enable in JAXP 1.3 which instructs parsers, transformers to behave in a secure fashion. You can find more information here: https://jaxp.java.net/1.4/JAXP-Compatibility.html#JAXP_security. For me 2 solutions worked out: Solution 1: With code change or implemenetation: //Create SchemaFactory using XSD file SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_UR...