|
Nokia N97 SDK Example Applications Guide |
00001 /* 00002 * XEDOMNSPROCESSING.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 <e32base.h> 00009 #include "XeDomExample.h" 00010 00011 00012 /************************************************************ 00013 * This example demonstrates how namespaces can be dealt 00014 * with in XML Engine DOM. It covers looking up for namespace 00015 * URIs, prefixes, retrieving the default namespace uris, 00016 * checking for NS URIs for a given prefix, creating a NS 00017 * prefix & URI, addding a NS declaration onto an element etc. 00018 **************************************************************/ 00019 00020 EXPORT_C void CXEDomEx::NsProcessingExampleL() 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 } 00087
|
© Nokia 2009 |