|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * XEDOMPARSENSAVE.CPP 00003 * Copyright (c) 2007 Nokia Corporation. 00004 * This material, including documentation and any related computer 00005 * programs,is protected by copyright controlled by Nokia Corporation. 00006 */ 00007 00008 #include "XeDomExample.h" 00009 00010 00011 /************************************************** 00012 * Demonstrates a simple parsing of an XML file and 00013 * return the document in tree form. Demonstrates 00014 * parsing a file as well as a buffer 00015 ***************************************************/ 00016 00017 EXPORT_C void CXEDomEx::ParseExampleL() 00018 { 00019 RXmlEngDocument document; 00020 TBuf<KFilePathSize> filepath(iDrive); 00021 _LIT(KFilename,"\\xedomexample\\input\\XML_parsing_001.xml"); 00022 filepath.Append(KFilename); 00023 TFileName srcFileName(filepath); 00024 00025 // The API for parsing a file, returns a handle to document 00026 document = iDomParser.ParseFileL(srcFileName); 00027 if(document.NotNull()) 00028 { 00029 // We have got the parsed dom tree,it can be used to access tree contents 00030 // using document APIs. 00031 TPtrC8 name = document.DocumentElement().Name(); 00032 00033 // finally closed by calling Close() 00034 document.Close(); 00035 } 00036 00037 00038 // Parse a buffer 00039 _LIT8(docW, "<doc>xmlns=\"http://test.pl\"><test>Test Content</test></doc>" ); 00040 RXmlEngDocument document2; 00041 TPtrC8 ptrW(docW); 00042 00043 // The API for parsing a buffer, returns a handle to document 00044 document2 = iDomParser.ParseL(ptrW); 00045 if(document2.NotNull()) 00046 { 00047 // Use the document tree and close it finally 00048 document2.Close(); 00049 } 00050 00051 } 00052 00053 /************************* 00054 * Demonstrates the saving 00055 * of an XML document onto 00056 * a given file or buffer 00057 **************************/ 00058 00059 EXPORT_C void CXEDomEx::SaveExampleL() 00060 { 00061 RXmlEngDocument document; 00062 TBuf<KFilePathSize> filepath(iDrive); 00063 _LIT(KFilename,"\\xedomexample\\input\\XML_parsing_001.xml"); 00064 filepath.Append(KFilename); 00065 TFileName srcFileName(filepath); 00066 00067 // Need to have a document tree for saving it 00068 // One way is get a parsed document 00069 document = iDomParser.ParseFileL(srcFileName); 00070 CleanupClosePushL(document); 00071 // The document can be modified now ... 00072 00073 //Save it to a file 00074 TBuf<KFilePathSize> filepath2(iDrive); 00075 _LIT(KFilename2, "\\xedomexample\\output\\XML_save_file.xml"); 00076 filepath2.Append(KFilename2); 00077 document.SaveL(filepath2); // The API to save (serialize) the document onto a file 00078 00079 //Save to a buffer 00080 _LIT8(encoding,"UTF-8"); 00081 TXmlEngSerializationOptions options(0, encoding); 00082 RBuf8 buffer; 00083 CleanupClosePushL(buffer); 00084 00085 // The API to save (serialize) the document onto a buffer 00086 // It can take different serialization options 00087 document.SaveL( buffer, document, options); 00088 00089 CleanupStack::PopAndDestroy(); //buffer 00090 CleanupStack::PopAndDestroy(); //document 00091 }
|
© Nokia 2009 |