Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VB & XML

Posted on 2002-05-24
5
Medium Priority
?
220 Views
Last Modified: 2010-05-02
Hi,
I am trying to add an xml string in the format "<problem><needHelp>problemId</needHelp></problem>"as well as adding the XML stored in another DOM into One single DOM to process. What I am doing at present is calling the below sub and passing in the element to add onto , the new name and the String or the DOM.xml respectively.  

However, the problem I am having is that when I add this onto the DOM the dom treats it as a text node and converts the < into &lt; and > into &gt;

In java I would use importNode is there a MSXML2 equivalent or is there a workaround.

Public Sub addValueElement(ByRef parent As MSXML2.IXMLDOMNode, name As String, value As Variant)

Dim doc As MSXML2.DOMDocument
Dim child As MSXML2.IXMLDOMElement
'get the owner Document of the Node
Set doc = parent.ownerDocument
'create the new Element
Set child = doc.createElement(name)
If value <> "" Then
    'give the element a child text node
    'containing the value
    child.appendChild doc.createTextNode(value)
End If
'append the child node onto the element
parent.appendChild child
End Sub
0
Comment
Question by:adamgernon
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7032357
Load the string "<problem><needHelp>problemId</needHelp></problem>" to a second XMLDocument (xml2).  Then use the appendChild method to load the documentElement from xml2

If this does not make any sense, I can give you some code.

Also, when you get a chance please maintain your open questions:
Questions Asked 40
Last 10 Grades Given A A A C B A A A B A  
Question Grading Record 27 Answers Graded / 27 Answers Received

Thanks,
Anthony
0
 

Author Comment

by:adamgernon
ID: 7032415
I tried this but It said u can have only one top level so if u wouldn't mind a small bit of code would be great
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 200 total points
ID: 7032671
I see what you mean (that comes from commenting without testing <g>).

Assuming that you have a main XML Document "<root/>" and you want to append "<problem><needHelp>problemId</needHelp></problem>", then the following code is what you need:

Dim xmlMainDoc As MSXML2.DOMDocument
Dim xmlFragDoc As MSXML2.DOMDocument

Set xmlMainDoc = New MSXML2.DOMDocument
If xmlMainDoc.loadXML("<root/>") Then
    Set xmlFragDoc = New MSXML2.DOMDocument
    If xmlFragDoc.loadXML("<problem><needHelp>problemId</needHelp></problem>") Then
        xmlMainDoc.documentElement.appendChild xmlFragDoc.documentElement
    End If
    Set xmlFragDoc = Nothing
    Debug.Print xmlMainDoc.xml
End If
Set xmlMainDoc = Nothing

If you want to add the child nodes somewhere else other than the <root>, than first set that node using the SelectSingleNode method, for example, and then do the appendChild to that.

Again, let me know if this does not make any sense.

Anthony
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 7033405
Also I see you have maintained most of your open questions, but I believe you may have overlooked this one:
Word Programming in VB Date: 08/01/2001 07:03AM PST  
http://www.experts-exchange.com/jsp/qShow.jsp?ta=winprog&qid=20161553

Anthony


0
 

Author Comment

by:adamgernon
ID: 7038983
thanks for ur help (and the gentle reminder)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question