02-27-2023 01:22 PM
I haven't had to do much XML processing with LabVIEW before and am trying to construct a SOAP web service request. Is it safe to use Coerce to Type to convert a Node refnum (returned by Get First Matched Node) to an Element refnum? None of the built-in examples show a recommended way to do this.
It's just a lot more convenient to look up an Element with XPath and use the Set Attribute method, rather than Create Attribute, Create Text Node, append the text node as a child of the attribute, look up the Node, get its attributes, then call Set Named Item to add the new attribute.
02-27-2023 03:37 PM
If you have a constant of the Node type and right click it you can see that Node is the parent of Element:
There is also a Type property of the Node reference you can get that has these options:
These are almost but not a complete 1:1 match. I would speculate that anything that returns "Element_Node" as its Type property would be castable, but I can't prove it would be true 100% of the time.
As a side note, the built-in LabVIEW XML processing, while it is functional, is pretty slow when you start giving it large XML chunks. If you're only using small ones then you should be fine, but if you're using large ones (10k+ characters) I would strongly recommend looking into alternate XML libraries:
02-27-2023 04:01 PM
Right, I get that Element inherits from Node in the XML DOM and the Get First Matched Element has to return a Node, because it doesn't know what its XPath refers to. I do know that the XPath I'm using will cause GFME to return exactly one Element. If these were Node and Element classes, I'd be comfortable using To More Specific Class to change the type of the wire, but refnums are basically pointers to a memory location (as I understand it), so I'm not sure if it's safe to be changing their type like this.
02-28-2023 01:52 AM - edited 02-28-2023 01:52 AM
Real refnums in LabVIEW are a bit more than pointers. But there is a chance that some code hides a pointer behind a fake refnum, however that would disqualify such a library to be ported to 64-bit like that.
The XML DOM library uses real refnums and the worst that can happen is that the To More Specific returns an error. So try it out and if it works, you should be safe. If it doesn’t that Node is a Node and not an Element disguised as Node.
03-15-2023 10:08 AM
Thanks for the responses. Since it's not clear if it's safe to cast a refnum like this and I don't want to have it suddenly stop working right at runtime if the data changes, I decided to go with the more verbose method.