Resources | developer.brewmp.com Resources | developer.brewmp.com

Developer

resources

Using XML interfaces

Using Brew MP interfaces, an XML document can be built or parsed. A general description of how this is done is described in this section.

Building an XML document

In this example, the caller sends an XML document and invokes a series of builder functions to create an XML/WBXML document.

  1. The caller instantiates the XMLBuilder and begins constructing the XML document.
    IEnv_CreateInstance(piEnv, AEECLSID_XMLBuilder, (void **)&piSAXBuilder);
    
    ISAXBuilder_Begin(me->piSaxBuilder)
    
    
  2. To build a single element, it invokes StartElement to indicate the beginning. Then, it adds the value for that element. It completes the element by invoking EndElement.
    ISAXBuilder_StartElement(piSAXBuilder,"MsgID",NULL);
    ISAXBuilder_AddCharacters(piSAXBuilder,"1",std_strlen("1"));
    ISAXBuilder_EndElement(piSAXBuilder);
    
    
  3. It can also build nested Elements by invoking another StartElement before invoking EndElement for the first one.
    ISAXBuilder_StartElement(piSAXBuilder,"Item",NULL);
    ISAXBuilder_StartElement(piSAXBuilder,"Data",NULL);
    ISAXBuilder_AddCharacters(piSAXBuilder,"1",std_strlen("1"));
    ISAXBuilder_EndElement(piSAXBuilder);
    ISAXBuilder_EndElement(piSAXBuilder);
    
    
  4. After the desired document is complete, it invokes Commit to indicate that the document is complete.
    ISAXBuilder_Commit(piSAXBuilder);
    
    
  5. It can query the size of the document and retrieve it.
    ISAXBuilder_CurrentDocumentSize(piSAXBuilder, &nLen);
    ISAXBuilder_GetCurrentDocument(piSAXBuilder,ppData,&nLen);
    
    
  6. After this call, the caller has a reference to the XML buffer, and the buffer will be released automatically at the next call to GetCurrentDocument or when the builder is freed.

Note: See the relevant .h/idl file for example, per-class usage. The following implementations are available:

  • AEECLSID_CXMLBuilder
  • AEECLSID_CWBXMLBuilder

Parsing an XML document

In this example, the caller has an XML document and invokes a series of functions to parse an XML/WBXML document.

  1. The caller instantiates the XML parser.
    IEnv_CreateInstance(piEnv, AEECLSID_XMLParser, (void **)&piSAXParser);
    
    
  2. The caller defines the appropriate callback functions to handle the parsed data.
    ISAXParser_SetHandlers(piSAXParser, ISAXParser_StartElementHandler, 
                           ISAXParser_EndElementHandler,
                           ISAXParser_CharacterDataHandler, 
                           ISAXParser_ProcessingInstructionHandler, 
                           ISAXParser_DefaultHandler,
                           pUserData);
    
    
  3. The caller invokes Parse. Now, all the appropriate callbacks are called until all of the document is parsed.
    ISAXParser_Parse(piSaxParser, cpszBuf, nLength, bIsFinal);
    
    

    Note: See the relevant .h/idl file for example, per-class usage. The following implementations are available:

    • AEECLSID_CXMLParser
    • AEECLSID_CWBXMLParser