Groups | Blog | Home
all groups > dotnet xml > july 2003 >

dotnet xml : How to Insert a node in a namespacemanaged document


Rafaela K. Azinhal
7/11/2003 11:36:38 AM
Please, help me with following code snippet

' Load xml document
Dim xmlDoc As New XmlDocument()
xmlDoc.Load(http://localhost/VT/reports/VT_actual_owsPivotTable.xml)
' define namespacemanager
Dim xmlNs As New XmlNamespaceManager(xmlDoc.NameTable)
Dim nsUri As String = xmlDoc.DocumentElement.GetNamespaceOfPrefix("x")
xmlNs.AddNamespace("x", nsUri)
' create template node
Dim templateNode As XmlNode
Dim memberNode as XmlNode
Dim nameNode as XmlNode
Dim uNameNode as XmlNode
templateNode = xmlDoc.CreateNode(XmlNodeType.Element, "x:IncludedMember",
nsUri)
nameNode = xmlDoc.CreateNode(XmlNodeType.Element, "x:Name", nsUri)
templateNode.AppendChild(nameNode)
uNameNode = xmlDoc.CreateNode(XmlNodeType.Element, "x:UniqueName", nsUri)
templateNode.AppendChild(uNameNode)
' find insertion node
Dim pivotfieldNode as XmlNode
pivotfieldNode =
xmlDoc.SelectSingleNode("/xml/x:PivotTable/x:PivotField[x:SourceName='[WorkW
eek].[Day]']", xmlNs)
' create clone node
memberNode = templateNode.Clone
' update node value
nameNode = memberNode.SelectSingleNode("/x:IncludedMember/x:Name", xmlNs) '
<=== returns Nothing!!!
....

Strangely enough, xmlNs.LookupNamespace("x") return "" instead of the uri
"urn:schemas-microsoft-com:office:excel"

A partial content of the xml document :

<xml xmlns:x="urn:schemas-microsoft-com:office:excel">
<x:PivotTable>
....
<x:PivotField>
<x:Name>Day</x:Name>
<x:SourceName>[WorkWeek].[Day]</x:SourceName>
<x:Orientation>Column</x:Orientation>
<x:Position>3</x:Position>
<x:CompareOrderedMembersBy>Name</x:CompareOrderedMembersBy>
<x:IncludedMember>
<x:Name>4</x:Name>
<x:UniqueName>[WorkWeek].[All WorkWeek].[2003].[Week 27].[4]</x:UniqueName>
</x:IncludedMember>
</x:PivotField>
....
</x:PivotTable>
</xml>

Dare Obasanjo
7/12/2003 10:11:32 AM
You may be coming across the bug described at

http://support.microsoft.com/default.aspx?scid=kb;en-us;324996

--
This posting is provided "AS IS" with no warranties, and confers no rights.

[quoted text, click to view]

AddThis Social Bookmark Button