Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VB & XML

Posted on 2002-05-24
5
Medium Priority
?
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

715 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