|
Nokia N97 SDK Example Applications Guide |
#include <XeDomExample.h>
Inheritance diagram for CXEDomEx:

Definition at line 26 of file XeDomExample.h.
Public Types |
|
| enum | TMenuItems { EQuit = 0, EParsing, ESave, EDocProcess, ENsProcess, EAttributes, EElements, EContainer } |
Public Member Functions |
|
| virtual | ~CXEDomEx () |
| void | StartExampleL () |
| void | ParseExampleL () |
| void | SaveExampleL () |
| void | DocProcessingExampleL () |
| void | NsProcessingExampleL () |
| void | AttributesExampleL () |
| void | ElementsExampleL () |
| void | DataContainersExampleL () |
| void | CreateDocumentL () |
| void | SiblingOperationsL () |
| void | NodeListOperationsL () |
| void | AttributeOperationsL () |
| void | AddAttributesL () |
| void | AddRemoveElementsL () |
| void | SetElementTextL () |
| void | BinaryContainersL () |
| void | ExternalContainersL () |
Static Public Member Functions |
|
| static CXEDomEx * | NewLC () |
| static CXEDomEx * | NewL () |
Public Attributes |
|
| TBuf< 4 > | iDrive |
Private Member Functions |
|
| CXEDomEx (const TDesC &aTestName) | |
| void | ConstructL () |
| void | GetDriveLetterL () |
| TInt | GetSelection (const TDesC &ourPrompt, const TDesC &validChoices) |
| void | PressAnyKey () |
Static Private Member Functions |
|
| static HBufC8 * | ReadFileL (const TDesC &aFileName) |
Private Attributes |
|
| RTest | iTest |
| RXmlEngDOMImplementation | iDomImpl |
| RXmlEngDOMParser | iDomParser |
|
|
High level Use cases demonstrated in this application Definition at line 34 of file XeDomExample.h. 00035 { 00036 EQuit = 0, 00037 EParsing, 00038 ESave, 00039 EDocProcess, 00040 ENsProcess, 00041 EAttributes, 00042 EElements, 00043 EContainer 00044 };
|
|
|
Construction functions Definition at line 36 of file XeDomExample.cpp. References iDomImpl, iDomParser, and iTest. 00037 { 00038 iTest.Close(); 00039 iDomParser.Close(); 00040 iDomImpl.Close(); 00041 }
|
|
|
Internal support functions Definition at line 31 of file XeDomExample.cpp. References iTest. Referenced by NewLC().
|
|
|
Function to start the application Definition at line 156 of file XeDomExample.cpp. References AttributesExampleL(), DataContainersExampleL(), DocProcessingExampleL(), ElementsExampleL(), GetSelection(), iTest, NsProcessingExampleL(), ParseExampleL(), PressAnyKey(), and SaveExampleL(). 00157 { 00158 TBool done = EFalse; 00159 const TDesC *example = NULL; 00160 TInt err= KErrNone; 00161 00162 // Repeat until user selects quit 00163 while (!done) 00164 { 00165 iTest.Console()->ClearScreen(); 00166 _LIT(KSelectOption, " Select an option \n\n"); 00167 iTest.Printf(KSelectOption); 00168 00169 _LIT(KPossibleSelectionsText, " 1) Document Parsing\n 2) Document Saving\n 3) Document Processing\n 4) Namespace Processing\n 5) Attributes Access\n 6) Elements Access\n 7) Data Containers\n 0) Quit\n"); 00170 _LIT(KPossibleSelections,"12345670"); 00171 TInt selection = GetSelection(KPossibleSelectionsText, KPossibleSelections); 00172 00173 // Set the example method to demonstrate for the user 00174 _LIT(KParsing, "Document Parsing,"); 00175 _LIT(KSave, "Document Saving,"); 00176 _LIT(KDocProcess, "Document Processing,"); 00177 _LIT(KNsProcess, "Namespace Processing,"); 00178 _LIT(KAttributes, "Attributes Access,"); 00179 _LIT(KElements, "Elements Access,"); 00180 _LIT(KContainer, "Data Containers,"); 00181 _LIT(KQuit, "Example application exit..."); 00182 switch (selection) 00183 { 00184 case EParsing: 00185 TRAP(err, ParseExampleL()); 00186 example = &KParsing; 00187 break; 00188 00189 case ESave: 00190 TRAP(err, SaveExampleL()); 00191 example = &KSave; 00192 break; 00193 00194 case EDocProcess: 00195 TRAP(err, DocProcessingExampleL()); 00196 example = &KDocProcess; 00197 break; 00198 00199 case ENsProcess: 00200 TRAP(err, NsProcessingExampleL()); 00201 example = &KNsProcess; 00202 break; 00203 00204 case EAttributes: 00205 TRAP(err, AttributesExampleL()); 00206 example = &KAttributes; 00207 break; 00208 00209 case EElements: 00210 TRAP(err, ElementsExampleL()); 00211 example = &KElements; 00212 break; 00213 00214 case EContainer: 00215 TRAP(err, DataContainersExampleL()); 00216 example = &KContainer; 00217 break; 00218 00219 case EQuit: 00220 done = ETrue; 00221 iTest.Console()->Printf(KQuit); 00222 break; 00223 00224 default: 00225 ; 00226 } 00227 00228 if(!done) 00229 { 00230 _LIT(KPathNotFound, "Input/output path not found"); 00231 _LIT(KMsg1, "Error occurred, error code:%d\n "); 00232 _LIT(KMsg2, "%S\n executed successfully."); 00233 if(err == KErrPathNotFound) 00234 iTest.Console()->Printf(KPathNotFound); 00235 else 00236 { 00237 if(err != KErrNone) 00238 iTest.Console()->Printf(KMsg1, err); 00239 else 00240 iTest.Console()->Printf(KMsg2, example); 00241 } 00242 } 00243 00244 PressAnyKey(); 00245 } // while 00246 }
|
|
|
Demonstrates a simple parsing of an XML file and return the document in tree form. Demonstrates parsing a file as well as a buffer Definition at line 17 of file XeDomParsenSave.cpp. References iDomParser, and iDrive. Referenced by StartExampleL(). 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 }
|
|
|
Demonstrates the saving of an XML document onto a given file or buffer Definition at line 59 of file XeDomParsenSave.cpp. References iDomParser, and iDrive. Referenced by StartExampleL(). 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 }
|
|
|
Demonstrates the creation / buidling of a document from scratch. Also shows how to deal with the different nodes in the document and operations on a node list that can be done. Definition at line 17 of file XeDomDocProcessing.cpp. References CreateDocumentL(), NodeListOperationsL(), and SiblingOperationsL(). Referenced by StartExampleL(). 00018 { 00019 //creating a new document - sub example 00020 CreateDocumentL(); 00021 00022 // Perform some sibling operations 00023 SiblingOperationsL(); 00024 00025 // How to use node list 00026 NodeListOperationsL(); 00027 }
|
|
|
This example demonstrates how namespaces can be dealt with in XML Engine DOM. It covers looking up for namespace URIs, prefixes, retrieving the default namespace uris, checking for NS URIs for a given prefix, creating a NS prefix & URI, addding a NS declaration onto an element etc. Definition at line 20 of file XeDomNsProcessing.cpp. References iDomParser, and iDrive. Referenced by StartExampleL(). 00021 { 00022 RXmlEngDocument document; 00023 TBuf<KFilePathSize> filepath(iDrive); 00024 _LIT(KFilename, "\\xedomexample\\input\\XML_nsprocessing.xml"); 00025 filepath.Append(KFilename); 00026 TFileName srcFileName(filepath); 00027 00028 document = iDomParser.ParseFileL(srcFileName); 00029 CleanupClosePushL(document); 00030 TXmlEngElement element = document.DocumentElement().FirstChild().AsElement(); 00031 00032 _LIT8(uri, "http://test.com"); 00033 _LIT8(uriD, "http://test.pl"); 00034 _LIT8(pref, "testns"); 00035 00036 //Looks up NS URI for given prefix 00037 if(element.LookupNamespaceUriL(pref).Compare(uri)) 00038 { 00039 User::Leave(KErrGeneral); // or some appropriate error 00040 } 00041 00042 // Looks up for prefix for given URI 00043 if(element.LookupPrefixL(uri).Compare(pref)) 00044 { 00045 User::Leave(KErrGeneral); // or some appropriate error 00046 } 00047 00048 //Gets the default namespace URI 00049 if(element.DefaultNamespaceL().Uri().Compare(uriD)) 00050 { 00051 User::Leave(KErrGeneral); // or some appropriate error 00052 } 00053 00054 00055 //Checks whether an element has a NS declaration for the given prefix 00056 if(!document.DocumentElement().AsElement().HasNsDeclarationForPrefixL(pref)) 00057 { 00058 User::Leave(KErrGeneral); // or some appropriate error 00059 } 00060 00061 _LIT8(prefix2,"wrong"); 00062 _LIT8(uri2,"http://wrong.com"); 00063 00064 //Creates an NS declaration for the given element after searching 00065 //for its existence. 00066 element.FindOrCreateNsDeclL(uri2,prefix2); 00067 00068 00069 _LIT8(prefix3,"newns"); 00070 _LIT8(uri3,"http://newns.com"); 00071 element = element.NextSibling().AsElement(); 00072 00073 //Adds a namespace declaration for the element 00074 element.AddNamespaceDeclarationL(uri3,prefix3); 00075 00076 //Makes the element not to have a default namespace 00077 element.SetNoDefaultNamespaceL(); 00078 00079 //Save the document to verify manually 00080 TBuf<KFilePathSize> filepath2(iDrive); 00081 _LIT(KFilename2, "\\xedomexample\\output\\XML_nsprocessing_output.xml"); 00082 filepath2.Append(KFilename2); 00083 document.SaveL(filepath2); 00084 00085 CleanupStack::PopAndDestroy(); //document 00086 }
|
|
|
This example demonstrates how xml engine DOM deals with attributes. It shows checking an element whether it has an attribute, getting/setting attribute name/values, adding/removing attributes, creating/deleting an attribute node, copying attributes, attributes with namespaces etc. Definition at line 20 of file XeDomAttributes.cpp. References AddAttributesL(), and AttributeOperationsL(). Referenced by StartExampleL(). 00021 { 00022 // some basic attribute operations - subexample 00023 AttributeOperationsL(); 00024 00025 // different ways of adding attributes - subexample 00026 AddAttributesL(); 00027 }
|
|
|
This example deals with element class of XML engine DOM It shows adding of new elements with/without namespaces, creating elements with auto prefixes, removal of element nodes, setting content text for elements (both raw and escaped), fetching elements by their name, removing NS declarations of an elements etc. Definition at line 20 of file XeDomElements.cpp. References AddRemoveElementsL(), and SetElementTextL(). Referenced by StartExampleL(). 00021 { 00022 // some examples of adding and removing elements 00023 AddRemoveElementsL(); 00024 00025 // accessing element text - subexample 00026 SetElementTextL(); 00027 }
|
|
|
This example demonstrates usage of internal (binary)& external (chunk) data containers provided by XML engine DOM. Creation of these containers, fetching the contents of these containers, setting the contens of these containers, specifying offsets,size in case of external containers, getting the list of data containers for the document Definition at line 20 of file XeDomContainers.cpp. References BinaryContainersL(), and ExternalContainersL(). Referenced by StartExampleL(). 00021 { 00022 // usage of binary containers - subexample 00023 BinaryContainersL(); 00024 00025 // usage external containers - subexample 00026 ExternalContainersL(); 00027 }
|
|
|
Creating a new xml document from scratch Definition at line 29 of file XeDomDocProcessing.cpp. References iDomImpl, and iDrive. Referenced by DocProcessingExampleL(). 00030 { 00031 _LIT8(name,"doc"); 00032 _LIT8(uri,"http://test.com"); 00033 _LIT8(arg1,"1.0"); 00034 _LIT8(arg2,"http://test2.org"); 00035 _LIT8(elename,"test"); 00036 00037 RXmlEngDocument document; 00038 document.OpenL(iDomImpl); 00039 CleanupClosePushL(document); 00040 00041 //Create a new document 00042 TXmlEngElement docEle = document.CreateDocumentElementL(name); // Creates and returns a document element 00043 document.DocumentElement().SetDefaultNamespaceL(uri); // Sets the default namespace of the document 00044 document.SetStandalone(TRUE); // Sets the standalone status of the document 00045 document.SetXmlVersionL(arg1); // Sets the XML version 00046 document.SetDocumentUriL(arg2); // Sets the document URI 00047 00048 TXmlEngElement ele= document.CreateElementL(elename); // Creates an element node 00049 docEle.AppendChildL(ele); // And make the element node a child to the document 00050 00051 //Save the document to verify manually 00052 TBuf<KFilePathSize> filepath(iDrive); 00053 _LIT(KFilename, "\\xedomexample\\output\\XML_createdoc_output.xml"); 00054 filepath.Append(KFilename); 00055 document.SaveL(filepath); 00056 00057 CleanupStack::PopAndDestroy(); //document 00058 }
|
|
|
Perform some sibling operations, e.g. move around the position of sibling nodes Definition at line 61 of file XeDomDocProcessing.cpp. References iDomParser, and iDrive. Referenced by DocProcessingExampleL(). 00062 { 00063 RXmlEngDocument document; 00064 TBuf<KFilePathSize> filepath(iDrive); 00065 _LIT(KFilename, "\\xedomexample\\input\\XML_sibling_fns.xml"); 00066 filepath.Append(KFilename); 00067 TFileName srcFileName(filepath); 00068 00069 document = iDomParser.ParseFileL(srcFileName); 00070 CleanupClosePushL(document); 00071 00072 // Retrieves the doc. element 00073 TXmlEngElement element = document.DocumentElement(); 00074 TXmlEngNode node; 00075 00076 // Sets the first child as last 00077 element.FirstChild().SetAsLastSibling(); 00078 00079 // Sets the previous child of last child as first one 00080 element.LastChild().PreviousSibling().SetAsFirstSibling(); 00081 00082 //Moves the last but one child before the child next to first child 00083 node = element.FirstChild().NextSibling(); 00084 element.LastChild().PreviousSibling().MoveBeforeSibling(node); 00085 00086 //Moves the next to next sibling of first child after last but one sibling 00087 node = element.LastChild().PreviousSibling(); 00088 element.FirstChild().NextSibling().NextSibling().MoveAfterSibling(node); 00089 00090 //Save the document to verify manually 00091 TBuf<KFilePathSize> filepath2(iDrive); 00092 _LIT(KFilename2, "\\xedomexample\\output\\XML_check_sibling_fns.xml"); 00093 filepath2.Append(KFilename2); 00094 document.SaveL(filepath2); 00095 00096 CleanupStack::PopAndDestroy(); //document 00097 }
|
|
|
Shows how to use NodeList class Definition at line 100 of file XeDomDocProcessing.cpp. References iDomParser, and iDrive. Referenced by DocProcessingExampleL(). 00101 { 00102 RXmlEngDocument document; 00103 TBuf<KFilePathSize> filepath(iDrive); 00104 _LIT(KFilename, "\\xedomexample\\input\\XML_nodetree_modif.xml"); 00105 filepath.Append(KFilename); 00106 TFileName srcFileName(filepath); 00107 00108 document = iDomParser.ParseFileL(srcFileName); 00109 CleanupClosePushL(document); 00110 00111 TXmlEngNode node; 00112 RXmlEngNodeList<TXmlEngElement> nodeList; 00113 node = document.DocumentElement(); 00114 00115 // Gets all the chidren elements of current node ( root element) 00116 node.AsElement().GetChildElements(nodeList); 00117 00118 // Gets the no.of nodes in the list 00119 if(nodeList.Count()!=4) 00120 User::Leave(KErrGeneral); 00121 CleanupClosePushL(nodeList); 00122 00123 TXmlEngElement element; 00124 00125 // Returns next node 00126 element = nodeList.Next(); 00127 00128 // Check the name of first element 00129 _LIT8(name,"elem1"); 00130 if(element.Name().Compare(name)) 00131 User::Leave(KErrGeneral); 00132 00133 nodeList.Next(); 00134 nodeList.Next(); 00135 00136 // Checks whether there is a node 00137 if (nodeList.HasNext()) 00138 { 00139 element = nodeList.Next(); 00140 _LIT8(name1,"elem4"); 00141 if(element.Name().Compare(name1)) 00142 User::Leave(KErrGeneral); 00143 } 00144 00145 CleanupStack::PopAndDestroy(); //nodeList 00146 CleanupStack::PopAndDestroy(); //document 00147 }
|
|
|
Perform basic operation of attributes, i.e. getting/setting their values, removing etc Definition at line 29 of file XeDomAttributes.cpp. References iDomParser, and iDrive. Referenced by AttributesExampleL(). 00030 { 00031 RXmlEngDocument document; 00032 TBuf<KFilePathSize> filepath(iDrive); 00033 _LIT(KFilename, "\\xedomexample\\input\\XML_check_attrs.xml"); 00034 filepath.Append(KFilename); 00035 TFileName srcFileName(filepath); 00036 00037 document = iDomParser.ParseFileL(srcFileName); 00038 CleanupClosePushL(document); 00039 TXmlEngElement element = document.DocumentElement().FirstChild().AsElement(); 00040 00041 _LIT8(str,"attr2"); 00042 _LIT8(str2,"wrong"); 00043 _LIT8(str3,"tewt"); 00044 _LIT8(str4,"attr3"); 00045 00046 //Check whether this element has the given attribute 00047 if(!(element.HasAttributeL(str,KNullDesC8))) 00048 { 00049 User::Leave(KErrGeneral); // or some appropriate error 00050 } 00051 00052 //Gets the attribute node for the element 00053 TXmlEngAttr attr = element.AttributeNodeL(str,KNullDesC8); 00054 if(attr.Value().Compare(str3) != 0) 00055 { 00056 User::Leave(KErrGeneral); // or some appropriate error 00057 } 00058 00059 //Modify Attributes 00060 element = document.DocumentElement().FirstChild().AsElement(); 00061 00062 // Removes the attribute from the element 00063 element.RemoveAttributeL(str4,KNullDesC8); 00064 00065 // Sets value of attribute; attribute is created if there is no such attribute yet 00066 element.SetAttributeL(str,str2); 00067 00068 // Creates new attribute, 00069 TXmlEngAttr attr1 = document.CreateAttributeL(str4); 00070 00071 // Sets new value of the attribute. Provided new value will be escaped as needed. 00072 attr1.SetValueL(str4); 00073 00074 // Links attribute into tree (by setting the attribute node for the element) 00075 element.SetAttributeNodeL(attr1); 00076 00077 //Save the document to verify manually 00078 TBuf<KFilePathSize> filepath2(iDrive); 00079 _LIT(KFilename2, "\\xedomexample\\output\\XML_modifattrs_output.xml"); 00080 filepath2.Append(KFilename2); 00081 document.SaveL(filepath2); 00082 00083 CleanupStack::PopAndDestroy(); //document 00084 }
|
|
|
Shows how to add attributes in different ways Definition at line 86 of file XeDomAttributes.cpp. References iDomParser, and iDrive. Referenced by AttributesExampleL(). 00087 { 00088 RXmlEngDocument document; 00089 TBuf<KFilePathSize> filepath(iDrive); 00090 _LIT(KFilename, "\\xedomexample\\input\\XML_nsprocessing.xml"); 00091 filepath.Append(KFilename); 00092 TFileName srcFileName(filepath); 00093 00094 document = iDomParser.ParseFileL(srcFileName); 00095 CleanupClosePushL(document); 00096 TXmlEngElement element = document.DocumentElement().FirstChild().AsElement(); 00097 00098 _LIT8(str,"attr2"); 00099 _LIT8(str2,"wrong"); 00100 _LIT8(pref,"testns"); 00101 _LIT8(uri, "http://test.com"); 00102 00103 // Creates new attribute node 00104 element.AddNewAttributeL(str,str2); 00105 00106 // Creates new attributes using namespace in the scope, which has specified URI 00107 element.AddNewAttributeWithNsL(str,str2,uri); 00108 00109 element = element.NextSibling().AsElement(); 00110 00111 // Creates new attribute node using namespace of its parent element (this element) 00112 element.AddNewAttributeSameNsL(str,str2); 00113 00114 //Creates new attribute using namespace, which is bound to the specified prefix 00115 element.AddNewAttributeUsePrefixL(str2,str,pref); 00116 00117 _LIT8(str4,"attr3"); 00118 _LIT8(pref2,"testns2"); 00119 _LIT8(uri2, "http://test.com.pl"); 00120 element.AddNewAttributeL(str4,str2,uri2,pref2); 00121 00122 element = element.NextSibling().NextSibling().AsElement(); 00123 00124 // Resets element's attributes 00125 element.RemoveAttributes(); 00126 00127 // Copies attributes from another element 00128 element.CopyAttributesL(document.DocumentElement().FirstChild().AsElement()); 00129 00130 element = element.NextSibling().AsElement(); 00131 TXmlEngNamespace elementNs = element.FindOrCreateNsDeclL(uri2,pref2); 00132 element.AddNewAttributeL(str4,str,elementNs); 00133 00134 //Save the document to verify manually 00135 TBuf<KFilePathSize> filepath2(iDrive); 00136 _LIT(KFilename2, "\\xedomexample\\output\\XML_addattrs_output.xml"); 00137 filepath2.Append(KFilename2); 00138 document.SaveL(filepath2); 00139 00140 CleanupStack::PopAndDestroy(); //document 00141 }
|
|
|
Shows adding xml elements in different ways Definition at line 30 of file XeDomElements.cpp. References iDomParser, and iDrive. Referenced by ElementsExampleL(). 00031 { 00032 RXmlEngDocument document; 00033 TBuf<KFilePathSize> filepath(iDrive); 00034 _LIT(KFilename, "\\xedomexample\\input\\XML_nsprocessing.xml"); 00035 filepath.Append(KFilename); 00036 TFileName srcFileName(filepath); 00037 00038 document = iDomParser.ParseFileL(srcFileName); 00039 CleanupClosePushL(document); 00040 TXmlEngElement element = document.DocumentElement().FirstChild().AsElement(); 00041 00042 _LIT8(str,"element"); 00043 _LIT8(str2,"wrong"); 00044 _LIT8(pref,"testns"); 00045 _LIT8(uri, "http://test.com"); 00046 00047 // Adds child element with no namespace 00048 element.AddNewElementL(str); 00049 00050 // Performs lookup for the namespace declaration for specified namespace URI and 00051 // adds new child element with found namespace. 00052 element.AddNewElementWithNsL(str,uri); 00053 00054 element = element.NextSibling().AsElement(); 00055 00056 // Performs lookup for the namespace declaration for specified prefix and 00057 // adds new child element with found namespace. 00058 element.AddNewElementUsePrefixL(str2,pref); 00059 00060 _LIT8(str4,"element3"); 00061 element = element.NextSibling().NextSibling().AsElement(); 00062 00063 // Copies a list of elements.Elements are appended to the element's children list. 00064 element.CopyChildrenL(document.DocumentElement().FirstChild().AsElement()); 00065 00066 _LIT8(uri3, "http://test.test.pl"); 00067 element = element.NextSibling().AsElement(); 00068 00069 // Creates new child element; if there is no a prefix binding for new element's namespace, 00070 // a namespace decaration is created with generated prefix at specified element. 00071 element.AddNewElementAutoPrefixL(str4,uri3,document.DocumentElement()); 00072 00073 //Save the document to verify manually 00074 TBuf<KFilePathSize> filepath2(iDrive); 00075 _LIT(KFilename2, "\\xedomexample\\output\\XML_addelements_output.xml"); 00076 filepath2.Append(KFilename2); 00077 document.SaveL(filepath2); 00078 00079 // To demonstrate removing of an element 00080 TXmlEngNode node1 = document.DocumentElement(); 00081 TXmlEngNode node2 = node1.FirstChild().Unlink(); 00082 node2 = node1.LastChild().SubstituteForL(node2); 00083 node2.Remove(); 00084 node1.FirstChild().Remove(); 00085 00086 CleanupStack::PopAndDestroy(); //document 00087 }
|
|
|
Shows different ways of changing element's text Definition at line 89 of file XeDomElements.cpp. References iDomParser, and iDrive. Referenced by ElementsExampleL(). 00090 { 00091 RXmlEngDocument document; 00092 TBuf<KFilePathSize> filepath(iDrive); 00093 _LIT(KFilename, "\\xedomexample\\input\\XML_setelement_text.xml"); 00094 filepath.Append(KFilename); 00095 TFileName srcFileName(filepath); 00096 00097 document = iDomParser.ParseFileL(srcFileName); 00098 CleanupClosePushL(document); 00099 TXmlEngElement element = document.DocumentElement().FirstChild().AsElement(); 00100 00101 _LIT8(str4,"test"); 00102 if(element.Text().Compare(str4) != 0) 00103 { 00104 User::Leave(KErrGeneral); // or some appropriate error 00105 } 00106 00107 _LIT8(str,"new text"); 00108 _LIT8(str2," new added text"); 00109 _LIT8(str3,"test&test1;test"); 00110 00111 // Sets text contents for the element. Any child nodes are removed 00112 element.SetTextL(str); 00113 00114 // Adds text as a child of the element 00115 element.AddTextL(str2); 00116 00117 element = element.NextSibling().AsElement(); 00118 00119 // Sets text content of the element from escaped string. 00120 element.SetEscapedTextL(str3); 00121 00122 //Save the document to verify manually 00123 TBuf<KFilePathSize> filepath2(iDrive); 00124 _LIT(KFilename2, "\\xedomexample\\output\\XML_addelements_output.xml"); 00125 filepath2.Append(KFilename2); 00126 document.SaveL(filepath2); 00127 00128 CleanupStack::PopAndDestroy(); //document 00129 }
|
|
|
Shows usage of internal binary containers within XML document tree Definition at line 30 of file XeDomContainers.cpp. References iDomImpl, iDrive, and ReadFileL(). Referenced by DataContainersExampleL(). 00031 { 00032 _LIT8(KElementName,"doc"); 00033 _LIT8(KTarget,"test"); 00034 _LIT8(KComment,"test comment"); 00035 _LIT8(KValue,"test value"); 00036 _LIT8(KNamespace,"testNamespace"); 00037 _LIT8(KPrefix,"testPref"); 00038 _LIT8(KStringName,"doc"); 00039 _LIT8(KStringValue,"ATTR_value"); 00040 _LIT8(KStringText,"test content"); 00041 _LIT8(KCData,"test < test2 & \r\n> ;"); 00042 00043 RXmlEngDocument document; 00044 document.OpenL(iDomImpl); 00045 CleanupClosePushL(document); 00046 00047 // Preparing a document before we deal with binary containers 00048 TXmlEngElement docEle = document.CreateDocumentElementL( KElementName,KNullDesC8 ,KNullDesC8 ); 00049 TXmlEngTextNode textNode = document.CreateTextNodeL(KStringText); 00050 docEle.AppendChildL(textNode); 00051 TXmlEngCDATASection cdNode = document.CreateCDATASectionL(KCData); 00052 docEle.AppendChildL(cdNode); 00053 TXmlEngAttr atNode = document.CreateAttributeL(KStringName, KStringValue); 00054 docEle.AppendChildL(atNode); 00055 TXmlEngComment commentNode = document.CreateCommentL(KComment); 00056 docEle.AppendChildL(commentNode); 00057 TXmlEngProcessingInstruction piNode = document.CreateProcessingInstructionL(KTarget, KValue); 00058 docEle.AppendChildL(piNode); 00059 TXmlEngElement elementNode = document.CreateElementL(KElementName, KNamespace, KPrefix); 00060 docEle.AppendChildL(elementNode); 00061 00062 // Binary data to be read 00063 TBuf<KFilePathSize> filepath1(iDrive); 00064 _LIT(KFilename1, "\\xedomexample\\input\\test.doc"); 00065 filepath1.Append(KFilename1); 00066 00067 TBuf<KFilePathSize> filepath2(iDrive); 00068 _LIT(KFilename2, "\\xedomexample\\input\\test.jpg"); 00069 filepath2.Append(KFilename2); 00070 00071 HBufC8* str1; 00072 str1=ReadFileL(filepath1); 00073 CleanupStack::PushL(str1); 00074 00075 HBufC8* str2; 00076 str2=ReadFileL(filepath2); 00077 CleanupStack::PushL(str2); 00078 00079 _LIT8(data, "this is some kind of binary data"); 00080 _LIT8(data1, "this is another kind of binary data 123"); 00081 _LIT8(cid, "123456789@123456789"); 00082 00083 // Creates new binary container and copies the content string into it. 00084 // Pointer to the container is stored in the document's 00085 // data container list that can be fetched using GetDataContainerList(). 00086 TXmlEngBinaryContainer binData = document.CreateBinaryContainerL(cid,data); 00087 00088 // Sets contents of binary container 00089 binData.SetContentsL(data1); 00090 00091 // Get content of the container. 00092 TPtrC8 fetchedData = binData.Contents(); 00093 if(fetchedData.Compare(data1)) 00094 User::Leave(KErrGeneral); 00095 00096 // Check data size in bytes 00097 if(data1().Length() != binData.Size()) 00098 User::Leave(KErrGeneral); 00099 00100 _LIT8(cid2, "123456789@123456788"); 00101 TXmlEngBinaryContainer binData1 = document.CreateBinaryContainerL(cid2, *str1); 00102 binData1.SetContentsL(*str2); 00103 00104 _LIT8(cid3, "123456789@123456787"); 00105 TXmlEngBinaryContainer binData2 = document.CreateBinaryContainerL(cid3, *str2); 00106 binData2.SetContentsL(*str1); 00107 00108 RArray<TXmlEngDataContainer> binaryContainers; 00109 document.GetDataContainerList(binaryContainers); 00110 CleanupClosePushL(binaryContainers); 00111 00112 if(binaryContainers.Count() != 3) 00113 User::Leave(KErrGeneral); 00114 00115 CleanupStack::PopAndDestroy(); //binaryContainers 00116 CleanupStack::PopAndDestroy(str2); 00117 CleanupStack::PopAndDestroy(str1); 00118 CleanupStack::PopAndDestroy(); //document 00119 }
|
|
|
Shows usage of external binary containers i.e filec ontainers, chunk containers, within XML document tree Definition at line 123 of file XeDomContainers.cpp. References iDomImpl. Referenced by DataContainersExampleL(). 00124 { 00125 _LIT8(KElementName,"doc"); 00126 _LIT8(KTarget,"test"); 00127 _LIT8(KComment,"test comment"); 00128 _LIT8(KValue,"test value"); 00129 _LIT8(KNamespace,"testNamespace"); 00130 _LIT8(KPrefix,"testPref"); 00131 _LIT8(KStringName,"doc"); 00132 _LIT8(KStringValue,"ATTR_value"); 00133 _LIT8(KStringText,"test content"); 00134 _LIT8(KCData,"test < test2 & \r\n> ;"); 00135 00136 RXmlEngDocument document; 00137 document.OpenL(iDomImpl); 00138 CleanupClosePushL(document); 00139 00140 // Preparing an example document before we deal with binary containers 00141 TXmlEngElement docEle = document.CreateDocumentElementL( KElementName,KNullDesC8 ,KNullDesC8 ); 00142 TXmlEngTextNode textNode = document.CreateTextNodeL(KStringText); 00143 docEle.AppendChildL(textNode); 00144 TXmlEngCDATASection cdNode = document.CreateCDATASectionL(KCData); 00145 docEle.AppendChildL(cdNode); 00146 TXmlEngAttr atNode = document.CreateAttributeL(KStringName, KStringValue); 00147 docEle.AppendChildL(atNode); 00148 TXmlEngComment commentNode = document.CreateCommentL(KComment); 00149 docEle.AppendChildL(commentNode); 00150 TXmlEngProcessingInstruction piNode = document.CreateProcessingInstructionL(KTarget, KValue); 00151 docEle.AppendChildL(piNode); 00152 TXmlEngElement elementNode = document.CreateElementL(KElementName, KNamespace, KPrefix); 00153 docEle.AppendChildL(elementNode); 00154 00155 _LIT8(cid, "123456789@123456789"); 00156 _LIT8(cid1, "11111111@123456789"); 00157 _LIT8(cid2, "22222222@123456789"); 00158 _LIT8(cid3, "33333333@123456789"); 00159 _LIT(chunkName, "test chunk"); 00160 const TInt size = 1000; 00161 const TInt maxSize = 5000; 00162 const TInt offset = 100; 00163 const TInt binarySize = 500; 00164 00165 _LIT8(KText, "binary containers"); 00166 TXmlEngElement el = document.CreateElementL(KText); 00167 document.DocumentElement().AppendChildL(el); 00168 00169 RChunk chunk; 00170 chunk.CreateGlobal(chunkName, size, maxSize); 00171 CleanupClosePushL(chunk); 00172 00173 // Creates new chunk container that stores reference to memory chunk 00174 TXmlEngChunkContainer binData = document.CreateChunkContainerL(cid, chunk,offset, binarySize); 00175 el.AppendChildL(binData); 00176 TXmlEngChunkContainer binData1 = document.CreateChunkContainerL(cid1, chunk,offset, binarySize); 00177 el.AppendChildL(binData1); 00178 TXmlEngChunkContainer binData2 = document.CreateChunkContainerL(cid2, chunk,offset, binarySize); 00179 el.AppendChildL(binData2); 00180 TXmlEngChunkContainer binData3 = document.CreateChunkContainerL(cid3, chunk,offset, binarySize); 00181 el.AppendChildL(binData3); 00182 00183 RArray<TXmlEngDataContainer> list; 00184 CleanupClosePushL(list); 00185 00186 // Retrieves an array of data containers owned by this document. 00187 document.GetDataContainerList(list); 00188 if(list.Count()!=4) 00189 User::Leave(KErrGeneral); 00190 if(list[0].Cid().Compare(cid)!=0) 00191 User::Leave(KErrGeneral); 00192 00193 CleanupStack::PopAndDestroy(); //document 00194 CleanupStack::PopAndDestroy(); //chunk 00195 CleanupStack::PopAndDestroy(); //list 00196 }
|
|
|
Retrieves the installation drive letter and stores for future use, required for filepath names for test input/output files. Definition at line 58 of file XeDomExample.cpp. References iDrive. Referenced by ConstructL(). 00059 { 00060 #ifdef EUMALOR_ENV 00061 _LIT(KCDrive, "C:"); 00062 iDrive = KCDrive; 00063 #else 00064 RProcess thisProcess; 00065 TFileName myFileName = thisProcess.FileName(); 00066 RFs fs; 00067 User::LeaveIfError( fs.Connect() ); 00068 CleanupClosePushL(fs); 00069 00070 TParse fp; 00071 fs.Parse(myFileName, fp); 00072 iDrive = fp.Drive(); 00073 CleanupStack::PopAndDestroy(); //fs 00074 #endif 00075 }
|
|
||||||||||||
|
Used to present the user with a list of options (ourPrompt), and get their selection. The user selection is validated against the choices (validChoices) Definition at line 126 of file XeDomExample.cpp. References iTest. Referenced by StartExampleL(). 00128 { 00129 _LIT(KFormat1, "%S "); 00130 _LIT(KFormat2, "[%S] :"); 00131 TKeyCode key = EKeyNull; 00132 iTest.Console()->SetPos (0, iTest.Console()->WhereY ()); 00133 iTest.Console()->Printf(KFormat1, &aPrompt); 00134 iTest.Console()->Printf(KFormat2, &aValidChoices); 00135 TInt xPos = iTest.Console()->WhereX(); 00136 00137 TInt retVal = KErrNotFound; 00138 _LIT(KFormat3, "%c "); 00139 while (retVal == KErrNotFound) 00140 { 00141 key = iTest.Getch(); 00142 iTest.Console()->Printf(KFormat3, key); 00143 iTest.Console()->SetPos(xPos); 00144 if(KErrNotFound != aValidChoices.Locate((TChar)key)) // Check if the choice is valid 00145 { 00146 retVal = key - '0'; 00147 } 00148 } 00149 00150 _LIT(KNewLines, "\n\n"); 00151 iTest.Console()->Printf(KNewLines); 00152 return retVal; 00153 }
|
|
|
Displays the message "Press any key..." on screen and waits for any key press from user. Definition at line 96 of file XeDomExample.cpp. References iTest. Referenced by ConstructL(), and StartExampleL(). 00097 { 00098 _LIT(KPressAnyKey, "\nPress any key to continue"); 00099 iTest.Printf(KPressAnyKey); 00100 iTest.Getch(); 00101 }
|
|
|
Reads the file contents from given file and returns the contents in heap buffer Definition at line 103 of file XeDomExample.cpp. Referenced by BinaryContainersL(). 00104 { 00105 // open fs and file 00106 RFs fs; 00107 User::LeaveIfError( fs.Connect() ); 00108 CleanupClosePushL(fs); 00109 00110 RFile file; 00111 CleanupClosePushL(file); 00112 User::LeaveIfError(file.Open(fs, aFileName, EFileStream)); 00113 00114 TInt size=0; 00115 User::LeaveIfError(file.Size(size)); 00116 HBufC8* buf = HBufC8::NewLC(size); 00117 TPtr8 bufPtr = buf->Des(); 00118 User::LeaveIfError(file.Read(bufPtr)); 00119 00120 CleanupStack::Pop(buf); 00121 CleanupStack::PopAndDestroy(); //file 00122 CleanupStack::PopAndDestroy(); //fs 00123 return buf; 00124 }
|
|
|
Drive letter for input testdata Definition at line 181 of file XeDomExample.h. Referenced by AddAttributesL(), AddRemoveElementsL(), AttributeOperationsL(), BinaryContainersL(), ConstructL(), CreateDocumentL(), GetDriveLetterL(), NodeListOperationsL(), NsProcessingExampleL(), ParseExampleL(), SaveExampleL(), SetElementTextL(), and SiblingOperationsL(). |
|
© Nokia 2009 |