webservices/wsfragment/src/wslibxml2utils.cpp
changeset 0 62f9d29f7211
child 1 272b002df977
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/webservices/wsfragment/src/wslibxml2utils.cpp	Thu Jan 07 16:19:19 2010 +0200
@@ -0,0 +1,70 @@
+/*
+* Copyright (c) 2004-2005 Nokia Corporation and/or its subsidiary(-ies). 
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:        Utility for webservices
+*
+*/
+
+
+
+
+
+
+
+
+#include "wslibxml2utils.h"
+
+#include <libxml2_globals.h>
+#include <xmlengelement.h>
+#include <xmlengerrors.h>
+#include <xmlengxestd.h>
+
+#define INTERNAL_NODEPTR(aNodeObject)   (*reinterpret_cast<xmlNodePtr*>(&(aNodeObject)))
+#define INTERNAL_NSPTR(aNsDefObject)    (*reinterpret_cast<xmlNsPtr*>(&(aNsDefObject)))
+#define XE_ASSERT_DEBUG(assertion)  __ASSERT_DEBUG((assertion),  XmlEngLeaveL(KXmlEngErrWrongUseOfAPI))
+#define XE_ASSERT_ALWAYS(assertion) __ASSERT_ALWAYS((assertion), XmlEngLeaveL(KXmlEngErrNullNode))
+
+
+xmlChar* xmlCharFromDesC8L(const TDesC8& aDesc)
+    {
+    if(!aDesc.Length())
+        {
+        return NULL;
+        }
+    xmlChar* newContent = (xmlChar*)new(ELeave) TUint8[aDesc.Length() + 1];
+    *(Mem::Copy((TAny*)newContent, aDesc.Ptr(), aDesc.Length())) = 0;
+    return newContent;
+    }
+    
+EXPORT_C void WsXmlUtils::XmlEngRenameElementL(TXmlEngElement aElement, const TDesC8& aLocalName, 
+                               const TDesC8& aNamespaceUri, 
+                               const TDesC8& aPrefix)
+    {
+			xmlNodePtr element = INTERNAL_NODEPTR(aElement);
+
+    	XE_ASSERT_DEBUG( element->type == XML_ELEMENT_NODE );
+
+      const xmlChar* oldName = element->name;
+       	
+      XE_ASSERT_ALWAYS(aLocalName.Length());
+       	
+      element->name = xmlCharFromDesC8L(aLocalName);
+       	
+      xmlFree((void*)oldName );
+       	
+      if (aNamespaceUri.Length() || aPrefix.Length())
+        {
+        	TXmlEngNamespace ns = aElement.FindOrCreateNsDeclL(aNamespaceUri, aPrefix);
+          element->ns = INTERNAL_NSPTR(ns);
+      	}
+    }
\ No newline at end of file