Ureader.com  
Microsoft software help and Community
   home   |   control panel login   |   archive   |  
 
XML
data.xmlanalysis
mappoint.webservice
msf
msxml-webrelease
netmyservices.sdk
passport.sdk
soap
soapsdk
uddi.general
uddi.programming
uddi.specification
xml
xmlsqlwebrelease
xsl
  
 
date: Fri, 18 Apr 2008 18:35:00 +0200,    group: microsoft.public.xml        back       


help needed with namespace and clonenode   
Hi,

I need a bit of help preventing empty namespaces littering my xml 
output.
The goal of the routine is to concatenate seperate xml-files (or rather 
parts of) into one.

With CloneNode, copying node from the input xml-file to an output is 
easy. But empty xmlns-tags are added. These I need to avoid.

I'm extremely new at xml, so be gentle on the following sample code.

best regards
glenn

-----Input-----
<VATSENDING xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<VATRECORD>
		<RECNUM>001</RECNUM>
		<VATNUMBER>123456002</VATNUMBER>
	</VATRECORD>
</VATSENDING>
---------------
-----Output----
<VATSENDING xmlns="http://www.w3.org/2001/XMLSchema-instance">
	<VATRECORD xmlns="">             <<<<---- xmlns="" these offend
		<RECNUM>001</RECNUM>
		<VATNUMBER>123456002</VATNUMBER>
	</VATRECORD>
	<VATRECORD xmlns="">             <<<<---- xmlns="" these offend
		<RECNUM>002</RECNUM>
		<VATNUMBER>123456002</VATNUMBER>
	</VATRECORD>
	<VATRECORD xmlns="">             <<<<---- xmlns="" these offend
		<RECNUM>003</RECNUM>
		<VATNUMBER>123456002</VATNUMBER>
	</VATRECORD>
</VATSENDING>
---------------

-----
Sub testxml()

Dim o_XML_In As MSXML2.DOMDocument
Dim o_XML_Out As MSXML2.DOMDocument
Dim o_root As MSXML2.IXMLDOMElement
Dim o_XML_Elt As MSXML2.IXMLDOMElement
Dim o_XML_copy As MSXML2.IXMLDOMElement

Dim n_CNTID As Long

    Set o_XML_In = New MSXML2.DOMDocument
    With o_XML_In
        .async = False
        .validateOnParse = False
        .Load "in.xml"
    End With

'Element to duplicate
    Set o_XML_Elt = o_XML_In.documentElement.selectSingleNode
("VATRECORD")
    
'output file
    Set o_XML_Out = New MSXML2.DOMDocument
    With o_XML_Out
        .async = False
        .validateOnParse = False
    End With

'Create root element in output file
    Set o_root = o_XML_Out.createNode(1, "VATSENDING", 
"http://www.w3.org/2001/XMLSchema-instance")
    o_XML_Out.appendChild o_root

    Set o_root = o_XML_Out.documentElement
    
'as test, duplicate node a few times, but modify counter
    n_CNTID = 1
    While n_CNTID < 4
    
            Set o_XML_copy = o_XML_Elt.cloneNode(True)
            o_XML_copy.childNodes.Item(0).nodeTypedValue = Format
(n_CNTID, "000")
            
            o_root.appendChild o_XML_copy
            n_CNTID = n_CNTID + 1
    Wend
    o_XML_Out.Save "out.xml"
End Sub
date: Fri, 18 Apr 2008 18:35:00 +0200   author:   glenn

Google
 
Web ureader.com


    COPYRIGHT 2007, YARDI TECHNOLOGY LIMITED, ALL RIGHT RESERVE  |   contact us