473,396 Members | 1,871 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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.CreateNode(XmlNodeType.Element, "Body", "")
nodeTest1 = objXML.CreateElement("TestValue1")
nodeTest2 = objXML.CreateElement("TestValue2")

nodeTest1.InnerText = "ActualValue1"
nodeTest2.InnerText = "ActualValue2"

nodeBody.AppendChild(nodeTest1)
nodeBody.AppendChild(nodeTest2)

objXML.AppendChild(nodeBody)

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

Class Code:
-----------------
Public Function AddXMLHeader(ByVal 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.CreateNode(Xml.XmlNodeType.Element, "Header",
"")
nodeTimeStamp = xmlTemp.CreateNode(Xml.XmlNodeType.Element,
"TimeStamp", "")
nodeFileName = xmlTemp.CreateNode(Xml.XmlNodeType.Element,
"FileName", "")
nodeWrite = xmlTemp.CreateNode(Xml.XmlNodeType.Element,
strNodeName, "")

nodeTimeStamp.InnerText = Now
nodeFileName.InnerText = strFileName
nodeHeader.AppendChild(nodeTimeStamp)
nodeHeader.AppendChild(nodeFileName)

nodeWrite.AppendChild(nodeHeader)
nodeWrite.AppendChild(nodePassed) <<<<<<<<<<<<<<<<<<<

xmlTemp.AppendChild(nodeWrite)
Return xmlTemp
End Function
Dec 16 '06 #1
4 2680
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.CreateNode(Xml.XmlNodeType.Element,
strNodeName, "")

nodeTimeStamp.InnerText = Now
nodeFileName.InnerText = strFileName
nodeHeader.AppendChild(nodeTimeStamp)
nodeHeader.AppendChild(nodeFileName)

nodeWrite.AppendChild(nodeHeader)
nodeWrite.AppendChild(nodePassed) <<<<<<<<<<<<<<<<<<<

"Dave" <Da**@Canada.comwrote in message
news:tc********************************@4ax.com...
>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.CreateNode(XmlNodeType.Element, "Body", "")
nodeTest1 = objXML.CreateElement("TestValue1")
nodeTest2 = objXML.CreateElement("TestValue2")

nodeTest1.InnerText = "ActualValue1"
nodeTest2.InnerText = "ActualValue2"

nodeBody.AppendChild(nodeTest1)
nodeBody.AppendChild(nodeTest2)

objXML.AppendChild(nodeBody)

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

Class Code:
-----------------
Public Function AddXMLHeader(ByVal 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.CreateNode(Xml.XmlNodeType.Element, "Header",
"")
nodeTimeStamp = xmlTemp.CreateNode(Xml.XmlNodeType.Element,
"TimeStamp", "")
nodeFileName = xmlTemp.CreateNode(Xml.XmlNodeType.Element,
"FileName", "")
nodeWrite = xmlTemp.CreateNode(Xml.XmlNodeType.Element,
strNodeName, "")

nodeTimeStamp.InnerText = Now
nodeFileName.InnerText = strFileName
nodeHeader.AppendChild(nodeTimeStamp)
nodeHeader.AppendChild(nodeFileName)

nodeWrite.AppendChild(nodeHeader)
nodeWrite.AppendChild(nodePassed) <<<<<<<<<<<<<<<<<<<

xmlTemp.AppendChild(nodeWrite)
Return xmlTemp
End Function

Dec 16 '06 #2
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.AppendChild(nodePassed) <<<<<<<<<<<<<<<<<<<
nodeWrite.AppendChild(_
nodeWrite.OwnerDocument.ImportNode(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
http://JavaScript.FAQTs.com/
Dec 16 '06 #3
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 <ma*******@yahoo.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.AppendChild(nodePassed) <<<<<<<<<<<<<<<<<<<

nodeWrite.AppendChild(_
nodeWrite.OwnerDocument.ImportNode(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.
Dec 18 '06 #4
Ignore my last post. Your node.write.appendchild(node..... ) worked
like a charm.

Thanks for the help!

Dave

On Sat, 16 Dec 2006 16:11:57 +0100, Martin Honnen <ma*******@yahoo.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.AppendChild(nodePassed) <<<<<<<<<<<<<<<<<<<

nodeWrite.AppendChild(_
nodeWrite.OwnerDocument.ImportNode(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.
Dec 18 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ralf Wahner | last post by:
Dear Masters of XSLT Could I ask you for a clue on the following question? I'd like to use XSLT to transform an XML source file to LaTeX. In the following small example the <para> Element...
2
by: Eshrath | last post by:
Hi, What I am trying to do: ======================= I need to form a table in html using the xsl but the table that is formed is quite long and cannot be viewed in our application. So we are...
4
by: Jim Garrison | last post by:
I know how to use the name() function to access the name of the current node. How do I get the 'fully qualified' name, consisting of the path from the root to the current node? I.e. <a> <b>...
6
by: SHC | last post by:
Hi all, I created an application from the Console Application (.NET) of VC++ .NET 2003, and I did "Build" the application of the attached .cpp file, volcanoes.xml and geology.dtd on my VC++ .NET...
3
by: Robert Kane | last post by:
Good afternoon, I'm trying to set up a clustered DB2 v7.1 database on Redhat Linux 7.3. I've followed the instructions (as far as I know) in the accompanying documentation to set up the database...
0
by: Chris | last post by:
I have a customer who wants to send us a XML message like this: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">...
2
by: Luiz Vianna | last post by:
Hi folks, I got a problem that certainly someone had too. After a user request, I (my server) must process a lot of data that will expend some time. During this process I must inform the user...
3
by: Beryl Small | last post by:
Hi, I have a third party software that needs to send information to an .aspx page for processing to communicate with an SQL database. The software sends the information something like this: ...
1
by: Knut Saua Mathiesen | last post by:
Hi there. I am reprogrammed my astar* path finding algorithm in C to make it quicker. I am now trying to make python use this C extension, however I keep getting "Segmentation fault". Some of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.