pvNodeValue - BaseXmlDomNode
Gets and Sets the content of an XML node using a Variant variable
Type: Property
Access: Read/Write
Data Type: Variant
Parameters: None
Syntax
Property Variant pvNodeValue
| Access Type | Syntax |
|---|---|
| Read Access: | Get pvNodeValue to VariantVariable |
| Write Access: | Set pvNodeValue to VariantVariable/Value |
Description
Gets and Sets the content of an XML node using a Variant variable.
pvNodeValue works the same as psNodeValue, with the exception that it interacts directly with a Variant string variable. Data stored in the XML document is stored in Unicode format and data stored in a Variant variable is stored in Unicode format. Therefore, data can be transferred back and forth without needing to perform any character translation. In addition, because this does not go through the DataFlex string handler, there is less of a limit on the size of the data.
This is a reasonably low level property and must be used carefully, because just about any DataFlex manipulation of the Variant string will result in it being converted to regular string, which involves Unicode to OEM translation. For example, even getting the Length() of the variant string results in the variant being converted to an OEM string and the Length then being applied to that. (You could use VariantStringLength(), which does not involve any kind of string conversion.)
Also note that the meaning of an XML's Node Name (psNodeName) and Node Value (psNodeValue or pvNodeValue) is dependent on the XML node type. A node may be more granular than you might expect. Consider the following XML node segment.
<Software>DataFlex</Software>
This is not a single node with a name of "Software" and a value of "DataFlex". These are two nodes. The outer-node is an element node with the node value of "Software". This outer node contains a single child text node with a node value of "DataFlex". Therefore, the data text value of the "Software" element would be obtained as follows. Assume hoElement contains the "Software" element node.
Variant vData
Handle hoTextNode
// this would get the data "value" of the element
Get FirstChild of hoNode to hoTextNode
Get pvNodeValue of hoTextNode to vData
Send Destroy of hoTextNode
// this would set the data "value" of the element
Get FirstChild of hoNode to hoTextNode
Set pvNodeValue of hoTextNode to vData
Send Destroy of hoTextNode
As long as your data value can be translated between OEM and Unicode, you can use either psNodeValue or pvNodeValue. psNodeValue is easier to use in this situation. Actually, using psText of hoNode would be even simpler.
Get psText of hoNode to sData
If translation or string length is a concern you can use pvNodeValue.
As another example, these two methods will get the value of an element with a child text node and add an element to an XML document.
// get the data value of an element and returns it as a variant
Function ElementValuetoVar Handle hoNode Returns Variant
Variant vData
Integer hoTextNode
Get FirstChild of hoNode to hoTextNode
If hoTextNode begin
Get pvNodeValue of hoTextNode to vData
Send Destroy of hoTextNode
End
Function_Return vData
End_Function
// add element to parent node with element sTag name and vData as data
Procedure AddVarElement String sTag Variant vData Handle hoParentNode
Integer hoElement hoTextNode
Get AddElement of hoParentNode sTag "" to hoElement
Get FirstChild of hoElement to hoTextNode
Set pvNodeValue of hoTextNode to vData
Send Destroy of hoTextNode
Send Destroy of hoElement
End_Procedure
In this example, assume you will load a PDF file into memory, convert this to base64 and store it as an XML node.
Variant vBase64
Address aPdf
Integer iBinSize iVoid
String sName
// read in a binary file into a memory heap.
// see cSeqFileHelper for more on this function
Move "c:\TestIn.pdf" to sName
Get ReadBinFileToBuffer of oFileHelper sName (&iBinSize) to aPdf
If (not(aPdf)) Begin
Procedure_Return // file did not load.
End
// convert the binary to a variant and store it in the XML file as a base 64 encoded value
// see cCharTranslate for more on this function.
Get Base64EncodeToVariantStr of oCharTranslate aPdf iBinSize to vBase64
// create a child element of hRootOut based on the tag name and data
Send AddVarElement "Base64Data" vBase64 hoRootOut
Move (Free(aPdf)) to iVoid
See Also
cCharTranslate | Base64EncodeToVariantStr | ReadBinFileToBuffer