Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Incompatibility between two XML objects
Message
De
30/12/2005 06:32:25
 
 
À
29/12/2005 15:02:03
Information générale
Forum:
ASP.NET
Catégorie:
XML
Divers
Thread ID:
01081433
Message ID:
01081965
Vues:
7
Hi,

Glad you got it working. I wasn't sure whether the nested node required the prefix but I see from your code that they do (and you worked it out)

I would, however, be wary of using your GetXMLNode() function in a generic fashion - there's no guarantee that the scope of the namespace will apply to all nested nodes.

Regards,
Viv


>>I think the .NET implementation is the correct one. I think you'll need to use a namespace manager. Something like:
>>
>>Public oDOM As XmlDocument = New XmlDocument
>>oDOM.LoadXml(tcXML)
>>Public oNSMgr As XmlNameSpaceManager = New XmlNamespaceManager(oDom)
>>oNSMgr.AddNamespace("ns","http://www.mywebsite.com/services/core/transformation/transformationresults")
>>oDom.SelectSingleNode("ns:TransformationResults/Status")
>>
>
>Thanks, the namespace implementation was the key. Here is the new class:
>
>
>Imports System.IO
>Imports System.XML
>
>Public Class XML
>    Public oDOM As XmlDocument = New XmlDocument
>    Public oXMLNodeList As XmlNodeList
>    Public oNode As XmlNode
>    Public cNodeInnerText As String = ""
>    Public oXmlNameSpaceManager As XmlNamespaceManager
>    Public cXmlNameSpaceManager As String = ""
>
>    ' Get a XML node value
>    ' expC1 XML
>    ' expC2 Node
>    Public Function GetXMLNodeValue(ByVal tcXML As String, ByVal tcNode As String) As Boolean
>        Dim llSuccess As Boolean
>        Dim lcNode As String = ""
>        oDOM.LoadXml(tcXML)
>
>        ' If we have a namespace
>        If cXmlNameSpaceManager.Length > 0 Then
>            oXmlNameSpaceManager = New XmlNamespaceManager(oDOM.NameTable)
>            oXmlNameSpaceManager.AddNamespace("ns", cXmlNameSpaceManager)
>        End If
>
>        ' Select the node
>        If cXmlNameSpaceManager.Length = 0 Then
>            lcNode = tcNode
>            oNode = oDOM.SelectSingleNode(lcNode)
>        Else
>            lcNode = "//ns:" + Framework.StringFunction.StrTran(tcNode, "/", "/ns:")
>            oNode = oDOM.SelectSingleNode(lcNode, oXmlNameSpaceManager)
>        End If
>
>        ' See if we obtained the node
>        If oNode Is Nothing Then
>            Framework.App.cError = "The node " + tcNode + " does not exist."
>            Return False
>        End If
>
>        Try
>            cNodeInnerText = oNode.InnerText
>            llSuccess = True
>        Catch loError As Exception
>            Framework.App.ErrorSetup(loError)
>        End Try
>        Return llSuccess
>    End Function
>
>End Class
>
>
>I can call it like this:
>
>
>        Dim loXML As Framework.XML = New Framework.XML
>            loXML.cXmlNameSpaceManager = "http://www.mywebsite.com/services/core/transformation/transformationresults"
>            If loXML.GetXMLNodeValue(lcXML, "TransformationResults/FileTransformationResults/OutputFile") = False Then
>                lcHTML = lcHTML + "<TD ALIGN=RIGHT>" + Math.Round(((lnEnd - lnStart) / 10000000), 2).ToString("#0.00")
>                lcHTML = lcHTML + "<TD>Success with failure on renaming the file: " + Framework.App.cError
>                cHtml = lcHTML
>                Return False
>            End If
>
>
>So, basically, if I initialize cXmlNameSpaceManager property, the method will know to define a namespace and adjust the node string to call.
>
>Thanks
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform