LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Write XML in LabView (MSXML ?)

I'm trying to add information to existing XML file with MSXML
 
I successfully open and browse through the file (see attatch file)
My problem is to add new event
 
 
 
My current XML file is somthing like this and I want to add new Event Node and sub-information
<Sensor SerialNumber="L004-9999-99">
  <Event>
    <Name>Creation</Name>
    <Date>2005-10-14 10:10:30</Date>
    <Attriute Name="Model" Value="XYZ"/>
  </Event>

 
  <Event>
    <Name>Calibration</Name>
    <Date>2005-10-14 12:00:10</Date>
    <Attriute Name="Cool/Heat Source Model" Value="Hart"/>
    <Attriute Name="Cool/Heat Source SN" Value="123"/>
  </Event>
 
</Sensor>
0 Kudos
Message 1 of 13
(5,997 Views)
here is the file
0 Kudos
Message 2 of 13
(5,985 Views)

here is the source code in VB to create a element :

Dim xmlDoc As New Msxml2.DOMDocument30
Dim root As IXMLDOMElement
Dim newElem As IXMLDOMElement
xmlDoc.async = False
xmlDoc.loadXML "<root><child/></root>"
If (xmlDoc.parseError.errorCode <> 0) Then
   Dim myErr
   Set myErr = xmlDoc.parseError
   MsgBox("You have error " & myErr.reason)
Else
   Set root = xmlDoc.documentElement
   Set newElem = xmlDoc.createElement("NEW")
   root.childNodes.Item(0).appendChild newElem
   root.childNodes.Item(0).lastChild.Text = "123"
   MsgBox root.childNodes.Item(0).xml
End If

0 Kudos
Message 3 of 13
(5,973 Views)

There are 2 ways to do this,  The very easy way and the less easy (but not too hard way).

The easy way, treat it as a text file, read in the string, parse it splitting before the </sensor> token and concatenate the before match, new event and </sensor> strings, and overwrite the old .XML file (this  works well but is not so extensible).

 

The better method is to use the MSXML com reference.  Place a new refernence to the MSXML automation type, and follow the code from your VB script, replacing the set property and methods using property and method nodes under the activeX palet.

Hope this helps.

Paul

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
Message 4 of 13
(5,968 Views)
Actually I have done the save thing done in VB with MSXML and I've got a compil error (wrong wire) ??
 
Kind of weird, because It's the same as VB
 
 
0 Kudos
Message 5 of 13
(5,951 Views)
I don't have your VI so I'm not positive, but it looks like you are trying to wire a plural (childNodes) into a singular (newChild).
Message 6 of 13
(5,936 Views)
Here is the VI it may help
 
Thanks
Phil G
Opsens
 
0 Kudos
Message 7 of 13
(5,933 Views)
Yep, that's the problem. If you turn on the context help in LV and hover over the wire, you'll see the COM Interface. What is coming out of childNodes is IXMLDOMNodeList and what appendChild expects is a IXMLDOMNode. You are going to need to iterate over the NodeList and add them one at a time. Take a look at
 
 
If you take a look at the VB code you posted, you'll see that it is actually doing an Item(0) to only ever access the first child element.
Message 8 of 13
(5,913 Views)
Sorry about that I've got little error in the previous VI and Screen
 
Thanks for pointing me out
 
In fact what you told me doesn't solve my problem
 
Please refer to JPG
The IXMLDOMDocument createElement create a single element :
           in VB :  Set newElem = xmlDoc.createElement("NEW")
After I iterate to found single child node where I want to add the element
           IXMLDOMElement / ChildNodes / IXMLDOMNodeList.item (index 0)
           in VB :  root.childNodes.Item(0).
After that I  try to append the element   IXMLDONNode.appendChild
           in VB :  root.childNodes.Item(0).appendChild newElem
 
It seems to have type incompatibility because in VB it works well but in LabView they give me Broken Wire
Because the system wanted to have a Node but not an Element.
However VB does the conversion itself
 
Thanks
 
Phil G
 

Message Edited by PhilHip on 11-16-2005 03:05 PM

Download All
0 Kudos
Message 9 of 13
(5,883 Views)
Ah, now we are on a different issue. So, the problem here is that the output of one terminal is a IXMLDOMElement and the input is a IXMLDOMNode. Now, as it happens, the element is a derived from the node. However, LV currently doesn't handle that automatically - to it they are simply different interfaces. To help LV out in this situation, drop a Variant To Data node, pass in the IXMLDOMElement refnum and tell the VtoD node that what you want out is an IXMLDOMNode. This results in a QueryInterface call and the return of the right interface.
Message 10 of 13
(5,860 Views)