SDMParser

The SDMParser component is responsible for transforming between the different representations of OData structures, for example, parsing from XMLs to a Java Object or building XMLs from a Java Object.

List of Features

SDMParser Public APIs

ISDMParser

ISDMODataServiceDocument parseSDMODataServiceDocumentXML(String serviceDocumentXML) 
ISDMODataServiceDocument parseSDMODataServiceDocumentXML(InputStream stream)

ISDMODataSchema parseSDMODataSchemaXML(String schemaXML, ISDMODataServiceDocument serviceDocument)
ISDMODataSchema parseSDMODataSchemaXML(InputStream stream, ISDMODataServiceDocument serviceDocument)

List<ISDMODataEntry> parseSDMODataEntriesXML(String entriesXML, String collectionId, ISDMODataSchema schema) 
List<ISDMODataEntry> parseSDMODataEntriesXML(InputStream stream, String collectionId, ISDMODataSchema schema)

ISDMODataOpenSearchDescription parseSDMODataOpenSearchDescriptionXML(String openSearchDescriptionXML, String collectionId, ISDMODataServiceDocument serviceDocument) 
ISDMODataOpenSearchDescription parseSDMODataOpenSearchDescriptionXML(InputStream stream, String collectionId, ISDMODataServiceDocument serviceDocument)

ISDMODataError parseSDMODataErrorXML(String errorXML)
ISDMODataError parseSDMODataErrorXML(InputStream stream)

List<ISDMODataEntry> parseFunctionImportResultXML(String xml, ISDMODataFunctionImport functionImport, ISDMODataSchema schema) 
List<ISDMODataEntry> parseFunctionImportResultXML(InputStream stream, ISDMODataFunctionImport functionImport, ISDMODataSchema schema)

String buildSDMODataEntryXML(ISDMODataEntry entry) 
String buildSDMODataDocumentXML(ISDMParserDocument document)
	
ISDMParserDocument parseXML(String xml) 
ISDMParserDocument parseXML(InputStream stream)

Example

   try {
	//Parsing a feed or a single entry.
	//Assuming that schema and service document already parsed 
	//and collection selected
	List<ISDMODataEntry> entries =
		parser.parseODataEntriesXML(responseXML,collectionId,schema);
	//Assuming there is at least one entry in the feed.
	ISDMODataEntry entry = entries.get(0);
	//Retrieving the valid property meta data from the given SDMOdataSchema.
	List<ISDMODataProperty> properties = entry.getPropertiesData();
	//Assuming there is at least one property for the entry.
	ISDMODataProperty property = properties.get(0);
	boolean visibleInList = property.getAttribute("visible-in-list");
	String value;
	if (visibleInList) {
		value = property.getValue();
	} else {
		value = "invisible";
	}
   } catch(SDMParserException e) {}

Technical Details

The SDMParser component uses javax.xml.parsers.SAXParser as a parser engine, defining its own extension of org.xml.sax.helpers.DefaultHandler class as a handler for SAXParser.

The outcome documents of SDMParser are all optimized for persistence using SDMPersistence, implementing the ISDMPersistable interface.

To support optimized performance and ensure consistent behavior, SDMParser can persist parsing related data on the device. End users can not delete parser related persisted data, unless they uninstall the whole application. To set the default folder of SDMParser’s persistence, change the default value of the appropriate preference: PARSER_DEFAULTFOLDER_PATH (see more at the section about the SDMConfiguration component of the Android OData SDK).

Parsing related data is loaded during the initialization of the SDMParser component. This means that SDMParser must always be initialized before using the SDMParser documents.

As a result of parsing, SDMParser provides Java Object representations of the appropriate OData structures. Each such SDMOData Java Object is a representation of the appropriate Data XML and provides dynamic access to all of its elements and attributes. Besides the full access with the dynamic method, OData Java Objects provide interfaces for a more convenient access of data used in the most common scenarios.