Guest User

Untitled

a guest
Oct 18th, 2017
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.38 KB | None | 0 0
  1. <orders>
  2. <order>
  3. <orderinfo>
  4. <orderid>143310630</orderid>
  5. <status><![CDATA[pending]]></status>
  6. <state><![CDATA[new]]></state>
  7. <createdat>2017-05-08 19:22:21</createdat>
  8. <billingname><![CDATA[dd Knudsen]]></billingname>
  9. <billingfirstname><![CDATA[dd]]></billingfirstname>
  10. <billinglastname><![CDATA[Knudsen]]></billinglastname>
  11. <billingcity><![CDATA[Koebenhavn s]]></billingcity>
  12. <billingstreet><![CDATA[ddgade 55 st tv]]></billingstreet>
  13. <billingcountry><![CDATA[DK]]></billingcountry>
  14. <billingphone><![CDATA[34433444]]></billingphone>
  15. <billingpostcode><![CDATA[2300]]></billingpostcode><shippingname><![CDATA[Robin Knudsen]]></shippingname>
  16. <shippingfirstname><![CDATA[dd]]></shippingfirstname>
  17. <shippinglastname><![CDATA[Knudsen]]></shippinglastname>
  18. <shippingcity><![CDATA[Koebenhavn s]]></shippingcity>
  19. <shippingstreet><![CDATA[ddgade 55 st tv]]></shippingstreet>
  20. <shippingphone><![CDATA[34433444]]></shippingphone>
  21. <shippingpostcode><![CDATA[2300]]></shippingpostcode>
  22. <shippingcountry><![CDATA[DK]]></shippingcountry><shippingmethod><![CDATA[flatrate_flatrate]]></shippingmethod>
  23. <paymentmethod><![CDATA[checkmo]]></paymentmethod>
  24. <paymentmethodtitle><![CDATA[Check / Money order]]></paymentmethodtitle>
  25. <email><![CDATA[thomas@goodie22.dk]]></email>
  26. <shippingdescription><![CDATA[Flat Rate - Fixed]]></shippingdescription>
  27. </orderinfo>
  28. <items><item>
  29. <id><![CDATA[445]]></id>
  30. <product_id><![CDATA[2]]></product_id>
  31. <sku><![CDATA[0]]></sku>
  32. <name><![CDATA[GoodieboxSept14]]></name>
  33. <qty><![CDATA[1.0000]]></qty>
  34. <price>139.0000</price>
  35. <rowtotal>139.0000</rowtotal>
  36. <taxamount>0.0000</taxamount>
  37. <taxpercent>0.0000</taxpercent>
  38. <originalprice>139.0000</originalprice>
  39. <baseprice>139.0000</baseprice>
  40. <baseoriginalprice>139.0000</baseoriginalprice>
  41. <baserowtotal>139.0000</baserowtotal>
  42. <priceincltax>139.0000</priceincltax>
  43. <basepriceincltax>139.0000</basepriceincltax>
  44. <rowtototalincltax>139.0000</rowtototalincltax>
  45. <baserowtotoalincltax></baserowtotoalincltax>
  46. <weight>1.0000</weight>
  47. <rowweight>1.0000</rowweight>
  48. <product_type>simple</product_type>
  49. <parent_item_id></parent_item_id>
  50. <product_options><![CDATA[a:1:{s:15:"info_buyRequest";a:2:{s:3:"qty";i:1;s:7:"options";a:0:{}}}]]></product_options>
  51. </item>
  52. </items>
  53. <basetotalinvoiced></basetotalinvoiced>
  54. <basetaxinvoiced></basetaxinvoiced>
  55. <baseshippinginvoiced></baseshippinginvoiced>
  56. <basetotalrefunded></basetotalrefunded>
  57. <basetaxrefunded></basetaxrefunded>
  58. <baseshippingrefunded></baseshippingrefunded>
  59. <basetoglobalrate>1.0000</basetoglobalrate>
  60. <discountamount>0.0000</discountamount>
  61. <shippingamount>5.0000</shippingamount>
  62. <grandtotal>144.0000</grandtotal>
  63. <basesubtotal>139.0000</basesubtotal>
  64. <taxamount>0.0000</taxamount>
  65. <basetaxamount>0.0000</basetaxamount>
  66. <basegrandtotal>144.0000</basegrandtotal>
  67. <totalpaid></totalpaid>
  68. <baseshippingtaxamount>0.0000</baseshippingtaxamount>
  69.  
  70. <weight>1.0000</weight>
  71. <subtotal>139.0000</subtotal>
  72. <basesubtotalincltax>139.0000</basesubtotalincltax>
  73. <totalitemcount>1</totalitemcount>
  74. <totalqtyordered>1.0000</totalqtyordered>
  75. <shippingincltax>5.0000</shippingincltax>
  76. <subtotalincltax>139.0000</subtotalincltax>
  77. <baseshippingincltax>5.0000</baseshippingincltax>
  78. <basetotalpaid></basetotalpaid><comments><item><entityid>45861</entityid><parentid>446</parentid><iscustomernotified>0</iscustomernotified><isvisibleonfront>0</isvisibleonfront><comment><![CDATA[]]></comment><status><![CDATA[pending]]></status><createdat><![CDATA[2017-05-08 19:22:21]]></createdat><entityname><![CDATA[order]]></entityname></item></comments></order>
  79.  
  80. </orders>
  81.  
  82. Sub MakeXML()
  83. ' create an XML file from an Excel table
  84. Dim MyRow As Integer, MyCol As Integer, Temp As String, YesNo As Variant, DefFolder As String
  85. Dim XMLFileName As String, XMLRecSetName As String, MyLF As String, RTC1 As Integer
  86. Dim RangeOne As String, RangeTwo As String, Tt As String, FldName(99) As String
  87. sheetname = ActiveSheet.Name
  88. Set ws = ThisWorkbook.Worksheets(sheetname)
  89. MyLF = Chr(10) & Chr(13) ' a line feed command
  90. DefFolder = Application.ActiveWorkbook.Path '"C:" 'change this to the location of saved XML files
  91.  
  92. 'MsgBox DefFolder
  93.  
  94. XMLFileName = "data_export.xml" 'FillSpaces(InputBox("1. Enter the name of the XML file:", "MakeXML CiM", "xl_xml_data"))
  95. If Right(XMLFileName, 4) <> ".xml" Then
  96. XMLFileName = XMLFileName & ".xml"
  97. End If
  98.  
  99. XMLRecSetName = "orderinfo" 'FillSpaces(InputBox("2. Enter an identifying name of a record:", "MakeXML CiM", "orderinfo"))
  100. 'MsgBox Cells(1, Columns.Count).End(xlToLeft).Column
  101. RangeOne = "A1:N1" 'InputBox("3. Enter the range of cells containing the field names (or column titles):", "MakeXML CiM", "A3:D3")
  102.  
  103. MyRow = MyRng(RangeOne, 1)
  104. For MyCol = MyRng(RangeOne, 3) To MyRng(RangeOne, 4)
  105. If Len(Cells(MyRow, MyCol).Value) = 0 Then
  106. MsgBox "Error: names range contains blank cell" & MyLF & "Procedure STOPPED", vbOKOnly + vbCritical, "MakeXML CiM"
  107. Exit Sub
  108. End If
  109. FldName(MyCol - MyRng(RangeOne, 3)) = FillSpaces(Cells(MyRow, MyCol).Value)
  110. Next MyCol
  111.  
  112. RangeTwo = "A2:N3" 'InputBox("4. Enter the range of cells containing the data table:", "MakeXML CiM", "A4:D8")
  113.  
  114. If MyRng(RangeOne, 4) - MyRng(RangeOne, 3) <> MyRng(RangeTwo, 4) - MyRng(RangeTwo, 3) Then
  115. MsgBox "Error: number of field names <> data columns" & MyLF & "Procedure STOPPED", vbOKOnly + vbCritical, "MakeXML CiM"
  116. Exit Sub
  117. End If
  118. RTC1 = MyRng(RangeTwo, 3)
  119.  
  120. If InStr(1, XMLFileName, ":") = 0 Then
  121. XMLFileName = DefFolder & XMLFileName
  122. End If
  123.  
  124. Open XMLFileName For Output As #1
  125. Print #1, "<?xml version=" & Chr(34) & "1.0" & Chr(34) & " encoding=" & Chr(34) & "ISO-8859-1" & Chr(34) & "?>"
  126. Print #1, "<orders>"
  127.  
  128. For MyRow = MyRng(RangeTwo, 1) To MyRng(RangeTwo, 2)
  129. Print #1, "<" & XMLRecSetName & ">"
  130. For MyCol = RTC1 To MyRng(RangeTwo, 4)
  131. ' the next line uses the FormChk function to format dates and numbers
  132. 'Print #1, "<" & FldName(MyCol - RTC1) & ">" & RemoveAmpersands(FormChk(MyRow, MyCol)) & "</" & FldName(MyCol - RTC1) & ">"
  133. ' the next line does not apply any formatting
  134. Print #1, "<" & FldName(MyCol - RTC1) & ">" & RemoveAmpersands(Cells(MyRow, MyCol).Value) & "</" & FldName(MyCol - RTC1) & ">"
  135. Next MyCol
  136. Print #1, "</" & XMLRecSetName & ">"
  137.  
  138. Next MyRow
  139. Print #1, "</orders>"
  140. Close #1
  141. MsgBox XMLFileName & " created." & MyLF & "Process finished", vbOKOnly + vbInformation, "MakeXML CiM"
  142. Debug.Print XMLFileName & " saved"
  143. End Sub
  144. Function Col_Letter(lngCol As Long) As String
  145. Dim vArr
  146. vArr = Split(Cells(1, lngCol).Address(True, False), "$")
  147. Col_Letter = vArr(0)
  148. End Function
  149. Function MyRng(MyRangeAsText As String, MyItem As Integer) As Integer
  150. ' analyse a range, where MyItem represents 1=TR, 2=BR, 3=LHC, 4=RHC
  151.  
  152. Dim UserRange As Range
  153. Set UserRange = Range(MyRangeAsText)
  154. Select Case MyItem
  155. Case 1
  156. MyRng = UserRange.Row
  157. Case 2
  158. MyRng = UserRange.Row + UserRange.Rows.Count - 1
  159. Case 3
  160. MyRng = UserRange.Column
  161. Case 4
  162. MyRng = UserRange.Columns(UserRange.Columns.Count).Column
  163. End Select
  164. Exit Function
  165.  
  166. End Function
  167. Function FillSpaces(AnyStr As String) As String
  168. ' remove any spaces and replace with underscore character
  169. Dim MyPos As Integer
  170. MyPos = InStr(1, AnyStr, " ")
  171. Do While MyPos > 0
  172. Mid(AnyStr, MyPos, 1) = "_"
  173. MyPos = InStr(1, AnyStr, " ")
  174. Loop
  175. FillSpaces = LCase(AnyStr)
  176. End Function
  177.  
  178. Function FormChk(RowNum As Integer, ColNum As Integer) As String
  179. ' formats numeric and date cell values to comma 000's and DD MMM YY
  180. FormChk = Cells(RowNum, ColNum).Value
  181. If IsNumeric(Cells(RowNum, ColNum).Value) Then
  182. FormChk = Format(Cells(RowNum, ColNum).Value, "#,##0 ;(#,##0)")
  183. End If
  184. If IsDate(Cells(RowNum, ColNum).Value) Then
  185. FormChk = Format(Cells(RowNum, ColNum).Value, "dd mmm yy")
  186. End If
  187. End Function
  188.  
  189. Function RemoveAmpersands(AnyStr As String) As String
  190. Dim MyPos As Integer
  191. ' replace Ampersands (&) with plus symbols (+)
  192.  
  193. MyPos = InStr(1, AnyStr, "&")
  194. Do While MyPos > 0
  195. Mid(AnyStr, MyPos, 1) = "+"
  196. MyPos = InStr(1, AnyStr, "&")
  197. Loop
  198. RemoveAmpersands = AnyStr
  199. End Function
Add Comment
Please, Sign In to add comment