webservices/wsfragment/src/wslibxml2utils.cpp
changeset 0 62f9d29f7211
child 1 272b002df977
equal deleted inserted replaced
-1:000000000000 0:62f9d29f7211
       
     1 /*
       
     2 * Copyright (c) 2004-2005 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:        Utility for webservices
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 
       
    22 
       
    23 
       
    24 
       
    25 #include "wslibxml2utils.h"
       
    26 
       
    27 #include <libxml2_globals.h>
       
    28 #include <xmlengelement.h>
       
    29 #include <xmlengerrors.h>
       
    30 #include <xmlengxestd.h>
       
    31 
       
    32 #define INTERNAL_NODEPTR(aNodeObject)   (*reinterpret_cast<xmlNodePtr*>(&(aNodeObject)))
       
    33 #define INTERNAL_NSPTR(aNsDefObject)    (*reinterpret_cast<xmlNsPtr*>(&(aNsDefObject)))
       
    34 #define XE_ASSERT_DEBUG(assertion)  __ASSERT_DEBUG((assertion),  XmlEngLeaveL(KXmlEngErrWrongUseOfAPI))
       
    35 #define XE_ASSERT_ALWAYS(assertion) __ASSERT_ALWAYS((assertion), XmlEngLeaveL(KXmlEngErrNullNode))
       
    36 
       
    37 
       
    38 xmlChar* xmlCharFromDesC8L(const TDesC8& aDesc)
       
    39     {
       
    40     if(!aDesc.Length())
       
    41         {
       
    42         return NULL;
       
    43         }
       
    44     xmlChar* newContent = (xmlChar*)new(ELeave) TUint8[aDesc.Length() + 1];
       
    45     *(Mem::Copy((TAny*)newContent, aDesc.Ptr(), aDesc.Length())) = 0;
       
    46     return newContent;
       
    47     }
       
    48     
       
    49 EXPORT_C void WsXmlUtils::XmlEngRenameElementL(TXmlEngElement aElement, const TDesC8& aLocalName, 
       
    50                                const TDesC8& aNamespaceUri, 
       
    51                                const TDesC8& aPrefix)
       
    52     {
       
    53 			xmlNodePtr element = INTERNAL_NODEPTR(aElement);
       
    54 
       
    55     	XE_ASSERT_DEBUG( element->type == XML_ELEMENT_NODE );
       
    56 
       
    57       const xmlChar* oldName = element->name;
       
    58        	
       
    59       XE_ASSERT_ALWAYS(aLocalName.Length());
       
    60        	
       
    61       element->name = xmlCharFromDesC8L(aLocalName);
       
    62        	
       
    63       xmlFree((void*)oldName );
       
    64        	
       
    65       if (aNamespaceUri.Length() || aPrefix.Length())
       
    66         {
       
    67         	TXmlEngNamespace ns = aElement.FindOrCreateNsDeclL(aNamespaceUri, aPrefix);
       
    68           element->ns = INTERNAL_NSPTR(ns);
       
    69       	}
       
    70     }