Sending an XML Node to a Function for Processing

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave

    Sending an XML Node to a Function for Processing

    I am trying to run a fucntion to add and format the final XML message.
    I tried passing the NodeBody to the Function (like I would have done
    with VB6) but a scope error.

    What's the best way to do this?


    Thanks


    Main Code:
    ------------------
    Dim objXML As New Xml.XmlDocument
    Dim nodeBody As Xml.XmlNode
    Dim nodeTest1 As Xml.XmlNode
    Dim nodeTest2 As Xml.XmlNode

    nodeBody = objXML.CreateNo de(XmlNodeType. Element, "Body", "")
    nodeTest1 = objXML.CreateEl ement("TestValu e1")
    nodeTest2 = objXML.CreateEl ement("TestValu e2")

    nodeTest1.Inner Text = "ActualValu e1"
    nodeTest2.Inner Text = "ActualValu e2"

    nodeBody.Append Child(nodeTest1 )
    nodeBody.Append Child(nodeTest2 )

    objXML.AppendCh ild(nodeBody)

    Dim xmlDave As New Xml.XmlDocument
    xmlDave = AddXMLHeader(no debody, "Test.XML", "TestXMLMessage ")



    Class Code:
    -----------------
    Public Function AddXMLHeader(By Val nodePassed As Xml.XmlNode, ByVal
    strFileName As String, ByVal strNodeName As String) As Xml.XmlDocument
    'This procedure will add a header and the main body of the XML
    message.
    '
    Dim xmlTemp As New Xml.XmlDocument
    Dim nodeHeader As Xml.XmlNode
    Dim nodeTimeStamp As Xml.XmlNode
    Dim nodeFileName As Xml.XmlNode
    Dim nodeWrite As Xml.XmlNode
    nodeHeader = xmlTemp.CreateN ode(Xml.XmlNode Type.Element, "Header",
    "")
    nodeTimeStamp = xmlTemp.CreateN ode(Xml.XmlNode Type.Element,
    "TimeStamp" , "")
    nodeFileName = xmlTemp.CreateN ode(Xml.XmlNode Type.Element,
    "FileName", "")
    nodeWrite = xmlTemp.CreateN ode(Xml.XmlNode Type.Element,
    strNodeName, "")

    nodeTimeStamp.I nnerText = Now
    nodeFileName.In nerText = strFileName
    nodeHeader.Appe ndChild(nodeTim eStamp)
    nodeHeader.Appe ndChild(nodeFil eName)

    nodeWrite.Appen dChild(nodeHead er)
    nodeWrite.Appen dChild(nodePass ed) <<<<<<<<<<<<<<< <<<<

    xmlTemp.AppendC hild(nodeWrite)
    Return xmlTemp
    End Function
  • Stephany Young

    #2
    Re: Sending an XML Node to a Function for Processing

    To clarify, the final XML should be structured likethis?:

    <Header>
    <TimeStamp />
    <FileName />
    <TestXMLMessage >
    <Body>
    <TestValue1 />
    <TestValue2 />
    </Body>

    </TestXMLMessage>
    </Header>

    If, not then draw us a picture please.

    nodeWrite = xmlTemp.CreateN ode(Xml.XmlNode Type.Element,
    strNodeName, "")
    >
    nodeTimeStamp.I nnerText = Now
    nodeFileName.In nerText = strFileName
    nodeHeader.Appe ndChild(nodeTim eStamp)
    nodeHeader.Appe ndChild(nodeFil eName)
    >
    nodeWrite.Appen dChild(nodeHead er)
    nodeWrite.Appen dChild(nodePass ed) <<<<<<<<<<<<<<< <<<<

    "Dave" <Dave@Canada.co mwrote in message
    news:tc17o25c08 429k152pe1rmsn8 cnd3u6dlq@4ax.c om...
    >I am trying to run a fucntion to add and format the final XML message.
    I tried passing the NodeBody to the Function (like I would have done
    with VB6) but a scope error.
    >
    What's the best way to do this?
    >
    >
    Thanks
    >
    >
    Main Code:
    ------------------
    Dim objXML As New Xml.XmlDocument
    Dim nodeBody As Xml.XmlNode
    Dim nodeTest1 As Xml.XmlNode
    Dim nodeTest2 As Xml.XmlNode
    >
    nodeBody = objXML.CreateNo de(XmlNodeType. Element, "Body", "")
    nodeTest1 = objXML.CreateEl ement("TestValu e1")
    nodeTest2 = objXML.CreateEl ement("TestValu e2")
    >
    nodeTest1.Inner Text = "ActualValu e1"
    nodeTest2.Inner Text = "ActualValu e2"
    >
    nodeBody.Append Child(nodeTest1 )
    nodeBody.Append Child(nodeTest2 )
    >
    objXML.AppendCh ild(nodeBody)
    >
    Dim xmlDave As New Xml.XmlDocument
    xmlDave = AddXMLHeader(no debody, "Test.XML", "TestXMLMessage ")
    >
    >
    >
    Class Code:
    -----------------
    Public Function AddXMLHeader(By Val nodePassed As Xml.XmlNode, ByVal
    strFileName As String, ByVal strNodeName As String) As Xml.XmlDocument
    'This procedure will add a header and the main body of the XML
    message.
    '
    Dim xmlTemp As New Xml.XmlDocument
    Dim nodeHeader As Xml.XmlNode
    Dim nodeTimeStamp As Xml.XmlNode
    Dim nodeFileName As Xml.XmlNode
    Dim nodeWrite As Xml.XmlNode
    nodeHeader = xmlTemp.CreateN ode(Xml.XmlNode Type.Element, "Header",
    "")
    nodeTimeStamp = xmlTemp.CreateN ode(Xml.XmlNode Type.Element,
    "TimeStamp" , "")
    nodeFileName = xmlTemp.CreateN ode(Xml.XmlNode Type.Element,
    "FileName", "")
    nodeWrite = xmlTemp.CreateN ode(Xml.XmlNode Type.Element,
    strNodeName, "")
    >
    nodeTimeStamp.I nnerText = Now
    nodeFileName.In nerText = strFileName
    nodeHeader.Appe ndChild(nodeTim eStamp)
    nodeHeader.Appe ndChild(nodeFil eName)
    >
    nodeWrite.Appen dChild(nodeHead er)
    nodeWrite.Appen dChild(nodePass ed) <<<<<<<<<<<<<<< <<<<
    >
    xmlTemp.AppendC hild(nodeWrite)
    Return xmlTemp
    End Function

    Comment

    • Martin Honnen

      #3
      Re: Sending an XML Node to a Function for Processing

      Dave wrote:
      I am trying to run a fucntion to add and format the final XML message.
      Use only on XmlDocument instance to create all the nodes. Or, if you
      need more than one XmlDocument instance then use ImportNode to import
      nodes created by one document into a second document e.g.
      nodeWrite.Appen dChild(nodePass ed) <<<<<<<<<<<<<<< <<<<
      nodeWrite.Appen dChild(_
      nodeWrite.Owner Document.Import Node(nodePassed , True))

      You need to use ImportNode any time you want to insert/append a node
      created by one document to a node created by a second document.




      --

      Martin Honnen --- MVP XML

      Comment

      • Dave

        #4
        Re: Sending an XML Node to a Function for Processing

        First, thanks for helping.

        The variable nodePassed is declared as xml.xmlnode. When I look at
        the details, it has the XML Text that I am looking form.

        When I perform the appendchild, I get an cannot import nodes of type
        'document'.

        Thanks,

        Dave

        On Sat, 16 Dec 2006 16:11:57 +0100, Martin Honnen <mahotrash@yaho o.de>
        wrote:
        >Dave wrote:
        >I am trying to run a fucntion to add and format the final XML message.
        >
        >Use only on XmlDocument instance to create all the nodes. Or, if you
        >need more than one XmlDocument instance then use ImportNode to import
        >nodes created by one document into a second document e.g.
        >
        > nodeWrite.Appen dChild(nodePass ed) <<<<<<<<<<<<<<< <<<<
        >
        nodeWrite.Appen dChild(_
        >nodeWrite.Owne rDocument.Impor tNode(nodePasse d, True))
        >
        >You need to use ImportNode any time you want to insert/append a node
        >created by one document to a node created by a second document.

        Comment

        • Dave

          #5
          Re: Sending an XML Node to a Function for Processing

          Ignore my last post. Your node.write.appe ndchild(node... .. ) worked
          like a charm.

          Thanks for the help!

          Dave

          On Sat, 16 Dec 2006 16:11:57 +0100, Martin Honnen <mahotrash@yaho o.de>
          wrote:
          >Dave wrote:
          >I am trying to run a fucntion to add and format the final XML message.
          >
          >Use only on XmlDocument instance to create all the nodes. Or, if you
          >need more than one XmlDocument instance then use ImportNode to import
          >nodes created by one document into a second document e.g.
          >
          > nodeWrite.Appen dChild(nodePass ed) <<<<<<<<<<<<<<< <<<<
          >
          nodeWrite.Appen dChild(_
          >nodeWrite.Owne rDocument.Impor tNode(nodePasse d, True))
          >
          >You need to use ImportNode any time you want to insert/append a node
          >created by one document to a node created by a second document.

          Comment

          Working...