Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Incompatibility between two XML objects
Message
De
30/12/2005 11:38:25
 
 
À
30/12/2005 06:32:25
Information générale
Forum:
ASP.NET
Catégorie:
XML
Divers
Thread ID:
01081433
Message ID:
01082030
Vues:
8
>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.

Last night, I adjusted the function to have it generic. So, this is what I have:
Imports System.IO
Imports System.XML

Public Class XML
    Public oXmlDocument As XmlDocument = New XmlDocument
    Public oXmlNameSpaceManager As XmlNamespaceManager
    Public oXmlNodeList As XmlNodeList
    Public oXmlNode As XmlNode
    Public oXmlElement As XmlElement
    Public cNodeInnerText As String = ""
    Public cXmlNameSpaceManager As String = ""
    Public cXmlNameSpaceManagerPrefix As String = ""
    Public cXML As String = ""
    Public cAttachment 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
        oXmlDocument.LoadXml(tcXML)

        ' If we have a namespace
        If cXmlNameSpaceManager.Length > 0 Then
            oXmlNameSpaceManager = New XmlNamespaceManager(oXmlDocument.NameTable)
            oXmlNameSpaceManager.AddNamespace(cXmlNameSpaceManagerPrefix, cXmlNameSpaceManager)
        End If

        ' Select the node
        If cXmlNameSpaceManager.Length = 0 Then
            oXmlNode = oXmlDocument.SelectSingleNode(tcNode)
        Else
            oXmlNode = oXmlDocument.SelectSingleNode(tcNode, oXmlNameSpaceManager)
        End If

        ' See if we obtained the node
        If oXmlNode Is Nothing Then
            Framework.App.cError = "The node " + tcNode + " does not exist."
            Return False
        End If

        Try
            cNodeInnerText = oXmlNode.InnerText
            llSuccess = True
        Catch loError As Exception
            Framework.App.ErrorSetup(loError)
        End Try
        Return llSuccess
    End Function

End Class
cXmlNameSpaceManagerPrefix has been added to the class. I can assign the value externally and can also decide on the global declaration on how it should be called.
            loXML.cXmlNameSpaceManager = "http://www.mywebsite.com/services/core/transformation/transformationresults"
            loXML.cXmlNameSpaceManagerPrefix = "ns"
            If loXML.GetXMLNodeValue(lcXML, "//ns:TransformationResults/ns:FileTransformationResults/ns: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
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform