patternMinor
Pulling information from XML to insert into Word Document inside 3rd party application
Viewed 0 times
insertpullingapplication3rdintopartyxmlworddocumentinside
Problem
This is code written for use inside a 3rd party application to pull information from an XML and insert into a word document, I don't know all the mechanics of the fun process of inserting the information into the word document (inside the 3rd party application) so some questions you might have for me are going to be answered with an "I don't know."
I haven't tested the code yet because it is pretty simple and I want to get changes into it before I have to shoot it to production.
and the XML that it is parsing is in the format
I haven't tested the code yet because it is pretty simple and I want to get changes into it before I have to shoot it to production.
Dim oNode
Dim oNodes
Set oNodes = XmlDoc.SelectNodes("/Record/Case/CaseFormsLoad/PartyLoad/Party/PartyPhones/Phone")
If oNodes.Length > 0 Then
For Each oNode In oNodes
If oNode.GetAttribute("ConfidentialFlag") = "True" Then
ReturnData = ReturnData & oNode.Getattribute("PhoneNum") & VbCrLf
End If
If ReturnData Is Nothing Then
ReturnData = ""
End If
Next
Else
ReturnData = ""
End Ifand the XML that it is parsing is in the format
Solution
A few remarks:
Variables:
I personally like declaring my Variables with a Type (the little safety needs to be used..). And while we're at it, I don't like having lists named as
Thus I personally(more emphasis) would rather do:
Conditionals
This if-statement evaluates to true only once. Instead you should initialize
Variables:
I personally like declaring my Variables with a Type (the little safety needs to be used..). And while we're at it, I don't like having lists named as
itemsThus I personally(more emphasis) would rather do:
Dim oNode As Variant
Dim oNodeList As VariantConditionals
If ReturnData Is Nothing Then
ReturnData = ""
EndIfThis if-statement evaluates to true only once. Instead you should initialize
ReturnData before your For Each and then you can completely remove it:Set oNodeList = 'shortcutting here
Dim ReturnData = "" As Variant/String
If oNodeList.Length > 0 Then
' carry onCode Snippets
Dim oNode As Variant
Dim oNodeList As VariantIf ReturnData Is Nothing Then
ReturnData = ""
EndIfSet oNodeList = 'shortcutting here
Dim ReturnData = "" As Variant/String
If oNodeList.Length > 0 Then
' carry onContext
StackExchange Code Review Q#49737, answer score: 4
Revisions (0)
No revisions yet.