Changeset 920
- Timestamp:
- Feb 2, 2014, 7:50:10 PM (11 years ago)
- Location:
- XmlTools2
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
XmlTools2/examples/BINACJBOCharacter.oni-patch
r919 r920 1 ######################################################################################### 2 ############################## XmlTools Patch File Example ############################## 3 ######################################################################################### 4 5 ########## Comments in patch files begin with '#' 6 7 ########## You can comment and uncomment commands to see their effect 8 ########## in BINACJBOCharacter.xml file 9 10 # The following row is always required in a XmlTools patch. 11 # It defines the minimum version of XmlTools executable that it requires. 1 12 @XML_TOOLS Version "2.0" 2 13 3 #@ADD_INSIDE_NODE ElementName "Particles" 4 <xml> 5 <Particle> 6 <Start>0</Start> 7 <End>45</End> 8 <Bone>Head</Bone> 9 <Name>glass_break</Name> 10 </Particle> 11 </xml> 12 13 @ADD_INSIDE_NODE ElementName "OSD" Files "BINACJBOCharacter-van.xml" 14 # This command adds a new XML node (inside of <xml></xml> tags) to all OSD named nodes. 15 @ADD_INSIDE_NODES ElementName "OSD" Files "BINACJBOCharacter.xml" 14 16 <xml> 15 17 <Attack> … … 28 30 </xml> 29 31 30 #@ADD_INSIDE_NODE ElementName "Attacks" 32 # This command removes the nodes inserted in the previous command using ElementName and ParentElementName. 33 @REMOVE_NODES ElementName "Attack" ParentElementName "OSD" Files "BINACJBOCharacter.xml" 34 35 # This command adds a new XML node (inside of <xml></xml> tags) to the nodes that matches the XPathExpression. 36 @ADD_INSIDE_NODES XPathExpression "/Oni/Objects/CHAR/OSD" Files "BINACJBOCharacter.xml" 31 37 <xml> 32 33 <Start>31</Start>34 <End>44</End>35 <Bones>Chest Neck LeftShoulder RightShoulder</Bones>36 37 38 <HitPoints>5</HitPoints>39 <HitType>HitBody</HitType>40 <HitLength>40</HitLength>41 42 43 <Extents/>44 38 <Attack> 39 <Start>0</Start> 40 <End>30</End> 41 <Bones>Pelvis Chest Neck Head LeftShoulder LeftArm LeftWrist LeftFist RightShoulder RightArm RightWrist RightFist</Bones> 42 <Flags>Unblockable</Flags> 43 <Knockback>0</Knockback> 44 <HitPoints>10</HitPoints> 45 <HitType>KnockdownBody</HitType> 46 <HitLength>0</HitLength> 47 <StunLength>0</StunLength> 48 <StaggerLength>0</StaggerLength> 49 <Extents/> 50 </Attack> 45 51 </xml> 46 52 47 #@ADD_INSIDE_NODE ElementName "Animation" 48 <xml> 49 <AttackRing> 50 <Length>0</Length> 51 <Length>0</Length> 52 <Length>0</Length> 53 <Length>0</Length> 54 <Length>0</Length> 55 <Length>0</Length> 56 <Length>0</Length> 57 <Length>0</Length> 58 <Length>0</Length> 59 <Length>0</Length> 60 <Length>0</Length> 61 <Length>0</Length> 62 <Length>0</Length> 63 <Length>0</Length> 64 <Length>0</Length> 65 <Length>0</Length> 66 <Length>0</Length> 67 <Length>0</Length> 68 <Length>0</Length> 69 <Length>0</Length> 70 <Length>0</Length> 71 <Length>0</Length> 72 <Length>0</Length> 73 <Length>0</Length> 74 <Length>0</Length> 75 <Length>0</Length> 76 <Length>0</Length> 77 <Length>0</Length> 78 <Length>0</Length> 79 <Length>0</Length> 80 <Length>0</Length> 81 <Length>0</Length> 82 <Length>0</Length> 83 <Length>0</Length> 84 <Length>0</Length> 85 <Length>0</Length> 86 </AttackRing> 87 </xml> 53 # This command removes the nodes inserted in the previous command using an XPathExpression. 54 @REMOVE_NODES XPathExpression "/Oni/Objects/CHAR/OSD/Attack" Files "BINACJBOCharacter.xml" 88 55 89 #@REMOVE_NODE ElementName "Objects" ParentElementName "Oni" Files "BINACJBOCharacter-van.xml" 56 # This command executes any of the XmlTools commands (see all possible command using XmlTools --help) 57 @COMMAND Arguments "--files 'BINACJBOCharacter.xml' --element-name 'Position' --invert-elements" 90 58 91 # @COMMAND "-?"59 # This command executes the javascript inside the (inside of <code></code> tags) 92 60 93 #@CUSTOM_CODE Files "BINACJBOCharacter-van.xml" 61 # The current javascript code first gets the element name "CHAR" with an attribute Id=11565 62 # then it gets the child element "OSD" and set its Weapon element value to "MyAwesomeOniWeapon" 63 @CUSTOM_CODE Files "BINACJBOCharacter.xml" 94 64 <code> 95 96 65 var myBuilder = new JSXMLBuilder(); 66 myBuilder.load($xmlData); 97 67 98 68 var elements = myBuilder.elements; 99 69 100 70 for (var i = 0; i < elements.length; i++) { -
XmlTools2/examples/BINACJBOCharacter.xml
r919 r920 1 <?xml version="1.0"?>2 1 <Oni> 3 2 <Objects> … … 5 4 <Header> 6 5 <Flags /> 7 <Position>2.23520136 AddedXmlTools2 -28.0006142</Position> 8 <Position>395.682281 AddedXmlTools2 161.52861</Position> 9 <Position>205.1952 AddedXmlTools2 37.781311</Position> 6 <Position>227.145248 756 -403.65567</Position> 10 7 <Rotation>0 184.086075 0</Rotation> 11 8 </Header> … … 78 75 <Header> 79 76 <Flags /> 80 <Position> 241.037384 AddedXmlTools2 -140.612183</Position>77 <Position>501.63855 756 223.189484</Position> 81 78 <Rotation>0 357.120178 0</Rotation> 82 79 </Header> … … 149 146 <Header> 150 147 <Flags /> 151 <Position> 326.930817 AddedXmlTools2 -224.495468</Position>148 <Position>-37.3426628 756 -491.6369</Position> 152 149 <Rotation>0 221.15564 0</Rotation> 153 150 </Header> … … 220 217 <Header> 221 218 <Flags /> 222 <Position> 61.4552727 AddedXmlTools2 -273.230347</Position>219 <Position>132.760071 756 247.212509</Position> 223 220 <Rotation>0 15.3564777 0</Rotation> 224 221 </Header> … … 291 288 <Header> 292 289 <Flags /> 293 <Position> -69.8346939 AddedXmlTools2 80.71216</Position>290 <Position>196.638962 756 -9.086177</Position> 294 291 <Rotation>0 40.0643044 0</Rotation> 295 292 </Header> … … 362 359 <Header> 363 360 <Flags /> 364 <Position> -78.57329 AddedXmlTools2 27.16457</Position>361 <Position>434.9334 756 -231.2183</Position> 365 362 <Rotation>0 258.058838 0</Rotation> 366 363 </Header> … … 433 430 <Header> 434 431 <Flags /> 435 <Position> -75.43486 AddedXmlTools2 -274.106232</Position>432 <Position>333.634979 756 -382.9142</Position> 436 433 <Rotation>0 170.885239 0</Rotation> 437 434 </Header> … … 504 501 <Header> 505 502 <Flags /> 506 <Position> 55.16015 AddedXmlTools2 -301.082275</Position>503 <Position>8.047889 756 -313.968872</Position> 507 504 <Rotation>0 111.10257 0</Rotation> 508 505 </Header> … … 575 572 <Header> 576 573 <Flags /> 577 <Position> 378.3339 AddedXmlTools2 -325.430664</Position>574 <Position>25.6273518 756 -279.1674</Position> 578 575 <Rotation>0 119.283485 0</Rotation> 579 576 </Header> … … 646 643 <Header> 647 644 <Flags /> 648 <Position> 431.155426 AddedXmlTools2 -183.092636</Position>645 <Position>228.093643 756 20.9510841</Position> 649 646 <Rotation>0 179.743469 0</Rotation> 650 647 </Header> … … 717 714 <Header> 718 715 <Flags /> 719 <Position> 427.98584 AddedXmlTools2 -165.537491</Position>716 <Position>228.657486 756 -0.173419476</Position> 720 717 <Rotation>0 179.743469 0</Rotation> 721 718 </Header> … … 788 785 <Header> 789 786 <Flags /> 790 <Position> 31.0909023 AddedXmlTools2 -150.9447</Position>787 <Position>227.516739 756 20.885685</Position> 791 788 <Rotation>0 179.743469 0</Rotation> 792 789 </Header> … … 859 856 <Header> 860 857 <Flags /> 861 <Position> -12.8269024 AddedXmlTools2 87.7636261</Position>858 <Position>449.521118 756 30.6618958</Position> 862 859 <Rotation>0 135.04158 0</Rotation> 863 860 </Header> … … 930 927 <Header> 931 928 <Flags /> 932 <Position> 303.549622 AddedXmlTools2 -71.6753</Position>929 <Position>-59.8743019 756 -399.768982</Position> 933 930 <Rotation>0 0.439508975 0</Rotation> 934 931 </Header> … … 1001 998 <Header> 1002 999 <Flags /> 1003 <Position> 305.288574 AddedXmlTools2 17.1488037</Position>1000 <Position>-34.60334 756 93.25939</Position> 1004 1001 <Rotation>0 95.61807 0</Rotation> 1005 1002 </Header> … … 1072 1069 <Header> 1073 1070 <Flags /> 1074 <Position> 183.626175 AddedXmlTools2 46.94594</Position>1071 <Position>-6.362502 756 79.95713</Position> 1075 1072 <Rotation>0 95.61807 0</Rotation> 1076 1073 </Header> … … 1143 1140 <Header> 1144 1141 <Flags /> 1145 <Position> 299.9704 AddedXmlTools2 -62.2183456</Position>1142 <Position>64.0541 681 148.629745</Position> 1146 1143 <Rotation>296.6574 302.560883 59.89215</Rotation> 1147 1144 </Header> … … 1214 1211 <Header> 1215 1212 <Flags>Locked</Flags> 1216 <Position> 419.398376 AddedXmlTools2 -295.7882</Position>1213 <Position>22.003334 756 132.236313</Position> 1217 1214 <Rotation>0 322.9601 0</Rotation> 1218 1215 </Header> … … 1285 1282 <Header> 1286 1283 <Flags /> 1287 <Position> 102.56255 AddedXmlTools2 -308.030457</Position>1284 <Position>278.8632 681 -387.586151</Position> 1288 1285 <Rotation>0 349.627716 0</Rotation> 1289 1286 </Header> … … 1356 1353 <Header> 1357 1354 <Flags /> 1358 <Position> 64.61314 AddedXmlTools2 -323.546844</Position>1355 <Position>181.788742 681 -393.361542</Position> 1359 1356 <Rotation>0 349.627716 0</Rotation> 1360 1357 </Header> … … 1427 1424 <Header> 1428 1425 <Flags /> 1429 <Position> 296.244873 AddedXmlTools2 -393.317719</Position>1426 <Position>-4.895431 681 -389.6944</Position> 1430 1427 <Rotation>0 10.2411852 0</Rotation> 1431 1428 </Header> … … 1498 1495 <Header> 1499 1496 <Flags /> 1500 <Position> 166.285965 AddedXmlTools2 -392.7305</Position>1497 <Position>332.7929 606 179.083817</Position> 1501 1498 <Rotation>0 157.0583 0</Rotation> 1502 1499 </Header> … … 1569 1566 <Header> 1570 1567 <Flags /> 1571 <Position> 40.4407272 AddedXmlTools2 135.503754</Position>1568 <Position>335.643677 681 125.508224</Position> 1572 1569 <Rotation>0 52.3811646 0</Rotation> 1573 1570 </Header> … … 1640 1637 <Header> 1641 1638 <Flags /> 1642 <Position>- 3.1352882 AddedXmlTools2 -21.6896744</Position>1639 <Position>-5.66062737 606 95.64748</Position> 1643 1640 <Rotation>0 272.65802 0</Rotation> 1644 1641 </Header> … … 1711 1708 <Header> 1712 1709 <Flags /> 1713 <Position>4 00.746246 AddedXmlTools2 -115.9501</Position>1710 <Position>44.2138252 531 10.4688931</Position> 1714 1711 <Rotation>0 66.02647 0</Rotation> 1715 1712 </Header> … … 1782 1779 <Header> 1783 1780 <Flags /> 1784 <Position> 338.9443 AddedXmlTools2 -203.975388</Position>1781 <Position>-25.2910767 531 70.29497</Position> 1785 1782 <Rotation>0 66.02647 0</Rotation> 1786 1783 </Header> … … 1853 1850 <Header> 1854 1851 <Flags /> 1855 <Position> 330.339661 AddedXmlTools2 -187.970078</Position>1852 <Position>-21.0974369 531 50.1971245</Position> 1856 1853 <Rotation>0 66.02647 0</Rotation> 1857 1854 </Header> … … 1924 1921 <Header> 1925 1922 <Flags /> 1926 <Position> 311.131744 AddedXmlTools2 -207.267319</Position>1923 <Position>27.2380466 531 -411.10495</Position> 1927 1924 <Rotation>0 253.804382 0</Rotation> 1928 1925 </Header> … … 1995 1992 <Header> 1996 1993 <Flags /> 1997 <Position> 346.280853 AddedXmlTools2 -331.994019</Position>1994 <Position>151.94664 531 116.959618</Position> 1998 1995 <Rotation>0 235.230042 0</Rotation> 1999 1996 </Header> … … 2066 2063 <Header> 2067 2064 <Flags /> 2068 <Position>4 6.78467 AddedXmlTools2 -374.001831</Position>2065 <Position>459.213684 531 0.507997155</Position> 2069 2066 <Rotation>0 235.901474 0</Rotation> 2070 2067 </Header> … … 2137 2134 <Header> 2138 2135 <Flags /> 2139 <Position> 305.4295 AddedXmlTools2 -382.098938</Position>2136 <Position>229.851837 531 23.1037388</Position> 2140 2137 <Rotation>0 0 0</Rotation> 2141 2138 </Header> … … 2208 2205 <Header> 2209 2206 <Flags /> 2210 <Position> 7.93541956 AddedXmlTools2 -96.3787</Position>2207 <Position>292.693085 606 133.571228</Position> 2211 2208 <Rotation>0 182.014313 0</Rotation> 2212 2209 </Header> … … 2279 2276 <Header> 2280 2277 <Flags /> 2281 <Position> 451.812225 AddedXmlTools2 -26.66731</Position>2278 <Position>163.6997 606 141.527542</Position> 2282 2279 <Rotation>0 161.312744 0</Rotation> 2283 2280 </Header> … … 2350 2347 <Header> 2351 2348 <Flags /> 2352 <Position> 3.890735 AddedXmlTools2 -154.496735</Position>2349 <Position>183.227264 -90 -194.548813</Position> 2353 2350 <Rotation>0 356.43103 0</Rotation> 2354 2351 </Header> … … 2421 2418 <Header> 2422 2419 <Flags>Locked</Flags> 2423 <Position> 63.1485329 AddedXmlTools2 -317.548126</Position>2420 <Position>110.12101 606 -436.5925</Position> 2424 2421 <Rotation>278.0008 315.1506 4.1193033E-07</Rotation> 2425 2422 </Header> … … 2492 2489 <Header> 2493 2490 <Flags /> 2494 <Position> 37.2282314 AddedXmlTools2 45.8681259</Position>2491 <Position>91.68629 681 4.790379</Position> 2495 2492 <Rotation>0 172.225037 0</Rotation> 2496 2493 </Header> … … 2563 2560 <Header> 2564 2561 <Flags /> 2565 <Position> 15.6102247 AddedXmlTools2 -56.1515961</Position>2562 <Position>338.480164 456 -121.213142</Position> 2566 2563 <Rotation>180.00032 198.85257 179.999084</Rotation> 2567 2564 </Header> … … 2634 2631 <Header> 2635 2632 <Flags /> 2636 <Position>3 50.422058 AddedXmlTools2 -323.086151</Position>2633 <Position>372.101746 456 40.79812</Position> 2637 2634 <Rotation>0 179.6179 0</Rotation> 2638 2635 </Header> … … 2705 2702 <Header> 2706 2703 <Flags /> 2707 <Position>3 73.392242 AddedXmlTools2 -287.778778</Position>2704 <Position>354.566376 456 42.4008026</Position> 2708 2705 <Rotation>197 0.382103026 180.000015</Rotation> 2709 2706 </Header> … … 2776 2773 <Header> 2777 2774 <Flags /> 2778 <Position>4 82.978058 AddedXmlTools2 -423.8415</Position>2775 <Position>447.2767 456 -137.319855</Position> 2779 2776 <Rotation>0 280.089661 0</Rotation> 2780 2777 </Header> … … 2847 2844 <Header> 2848 2845 <Flags /> 2849 <Position> 8.43173432 AddedXmlTools2 -181.413681</Position>2846 <Position>126.507782 420 40.5357132</Position> 2850 2847 <Rotation>0 86.98753 0</Rotation> 2851 2848 </Header> … … 2918 2915 <Header> 2919 2916 <Flags /> 2920 <Position>12 .7673929 AddedXmlTools2 -72.41088</Position>2917 <Position>127.074745 420 27.4937611</Position> 2921 2918 <Rotation>0 86.98753 0</Rotation> 2922 2919 </Header> … … 2989 2986 <Header> 2990 2987 <Flags /> 2991 <Position> 493.345673 AddedXmlTools2 -110.908844</Position>2988 <Position>-2.811713 420 -430.663269</Position> 2992 2989 <Rotation>0 42.64707 0</Rotation> 2993 2990 </Header> … … 3060 3057 <Header> 3061 3058 <Flags>Locked</Flags> 3062 <Position> 313.6454 AddedXmlTools2 -120.866913</Position>3059 <Position>57.87403 420 -182.203781</Position> 3063 3060 <Rotation>0 89.64752 0</Rotation> 3064 3061 </Header> … … 3131 3128 <Header> 3132 3129 <Flags /> 3133 <Position>4 11.392456 AddedXmlTools2 -212.415573</Position>3130 <Position>401.392456 396 -222.415573</Position> 3134 3131 <Rotation>0 40.3041229 0</Rotation> 3135 3132 </Header> … … 3202 3199 <Header> 3203 3200 <Flags /> 3204 <Position> 67.87403 AddedXmlTools2 -172.203781</Position>3201 <Position>303.6454 396 -130.866913</Position> 3205 3202 <Rotation>0 174.575058 0</Rotation> 3206 3203 </Header> … … 3273 3270 <Header> 3274 3271 <Flags /> 3275 <Position> 7.188287 AddedXmlTools2 -420.663269</Position>3272 <Position>483.345673 396 -120.908844</Position> 3276 3273 <Rotation>0 355.304 0</Rotation> 3277 3274 </Header> … … 3344 3341 <Header> 3345 3342 <Flags /> 3346 <Position> 137.074745 AddedXmlTools2 37.4937611</Position>3343 <Position>2.76739287 360 -82.41088</Position> 3347 3344 <Rotation>0 203.00119 0</Rotation> 3348 3345 </Header> … … 3415 3412 <Header> 3416 3413 <Flags /> 3417 <Position> 136.507782 AddedXmlTools2 50.5357132</Position>3414 <Position>-1.56826568 360 -191.413681</Position> 3418 3415 <Rotation>0 342.3229 0</Rotation> 3419 3416 </Header> … … 3486 3483 <Header> 3487 3484 <Flags /> 3488 <Position>4 57.2767 AddedXmlTools2 -127.319855</Position>3485 <Position>472.978058 336 -433.8415</Position> 3489 3486 <Rotation>0 306.1824 0</Rotation> 3490 3487 </Header> … … 3557 3554 <Header> 3558 3555 <Flags /> 3559 <Position>36 4.566376 AddedXmlTools2 52.4008026</Position>3556 <Position>363.392242 336 -297.778778</Position> 3560 3557 <Rotation>0 121.313988 0</Rotation> 3561 3558 </Header> … … 3628 3625 <Header> 3629 3626 <Flags /> 3630 <Position>3 82.101746 AddedXmlTools2 50.79812</Position>3627 <Position>340.422058 336 -333.086151</Position> 3631 3628 <Rotation>0 136.533173 0</Rotation> 3632 3629 </Header> … … 3699 3696 <Header> 3700 3697 <Flags /> 3701 <Position> 348.480164 AddedXmlTools2 -111.213142</Position>3698 <Position>5.61022472 300 -66.1515961</Position> 3702 3699 <Rotation>0 2.13530827 0</Rotation> 3703 3700 </Header> … … 3770 3767 <Header> 3771 3768 <Flags /> 3772 <Position> 101.68629 AddedXmlTools2 14.790379</Position>3769 <Position>27.2282314 300 35.8681259</Position> 3773 3770 <Rotation>0 2.13530827 0</Rotation> 3774 3771 </Header> … … 3841 3838 <Header> 3842 3839 <Flags /> 3843 <Position> 120.12101 AddedXmlTools2 -426.5925</Position>3840 <Position>53.1485329 300 -327.548126</Position> 3844 3841 <Rotation>0 62.22974 0</Rotation> 3845 3842 </Header> … … 3912 3909 <Header> 3913 3910 <Flags>Locked</Flags> 3914 <Position> 193.227264 AddedXmlTools2 -184.548813</Position>3911 <Position>-6.109265 300 -164.496735</Position> 3915 3912 <Rotation>0 172.236191 0</Rotation> 3916 3913 </Header> … … 3983 3980 <Header> 3984 3981 <Flags /> 3985 <Position> 173.6997 AddedXmlTools2 151.527542</Position>3982 <Position>441.812225 276 -36.66731</Position> 3986 3983 <Rotation>0 117.178528 0</Rotation> 3987 3984 </Header> … … 4054 4051 <Header> 4055 4052 <Flags /> 4056 <Position> 302.693085 AddedXmlTools2 143.571228</Position>4053 <Position>-2.06458044 240 -106.3787</Position> 4057 4054 <Rotation>0 298.2401 0</Rotation> 4058 4055 </Header> … … 4125 4122 <Header> 4126 4123 <Flags>Locked</Flags> 4127 <Position>2 39.851837 AddedXmlTools2 33.1037388</Position>4124 <Position>295.4295 240 -392.098938</Position> 4128 4125 <Rotation>0 322.411774 0</Rotation> 4129 4126 </Header> … … 4196 4193 <Header> 4197 4194 <Flags /> 4198 <Position> 469.213684 AddedXmlTools2 10.5079972</Position>4195 <Position>36.78467 240 -384.001831</Position> 4199 4196 <Rotation>0 33.47298 0</Rotation> 4200 4197 </Header> … … 4267 4264 <Header> 4268 4265 <Flags /> 4269 <Position> 161.94664 AddedXmlTools2 126.959618</Position>4266 <Position>336.280853 180 -341.994019</Position> 4270 4267 <Rotation>0 94.67434 0</Rotation> 4271 4268 </Header> … … 4338 4335 <Header> 4339 4336 <Flags /> 4340 <Position>3 7.2380466 AddedXmlTools2 -401.10495</Position>4337 <Position>301.131744 180 -217.267319</Position> 4341 4338 <Rotation>0 247.718018 0</Rotation> 4342 4339 </Header> … … 4409 4406 <Header> 4410 4407 <Flags /> 4411 <Position> -11.0974369 AddedXmlTools2 60.1971245</Position>4408 <Position>320.339661 180 -197.970078</Position> 4412 4409 <Rotation>0 247.718018 0</Rotation> 4413 4410 </Header> … … 4480 4477 <Header> 4481 4478 <Flags /> 4482 <Position> -15.2910767 AddedXmlTools2 80.29497</Position>4479 <Position>328.9443 180 -213.975388</Position> 4483 4480 <Rotation>0 247.718018 0</Rotation> 4484 4481 </Header> … … 4551 4548 <Header> 4552 4549 <Flags /> 4553 <Position> 54.2138252 AddedXmlTools2 20.4688931</Position>4550 <Position>390.746246 180 -125.9501</Position> 4554 4551 <Rotation>0 280.0558 0</Rotation> 4555 4552 </Header> … … 4622 4619 <Header> 4623 4620 <Flags /> 4624 <Position> 4.33937263 AddedXmlTools2 105.64748</Position>4621 <Position>-13.1352882 120 -31.6896744</Position> 4625 4622 <Rotation>0 106.310493 0</Rotation> 4626 4623 </Header> … … 4693 4690 <Header> 4694 4691 <Flags>Locked</Flags> 4695 <Position>3 45.643677 AddedXmlTools2 135.508224</Position>4692 <Position>30.4407272 0 125.503754</Position> 4696 4693 <Rotation>0 123.543991 0</Rotation> 4697 4694 </Header> … … 4764 4761 <Header> 4765 4762 <Flags /> 4766 <Position> 342.7929 AddedXmlTools2 189.083817</Position>4763 <Position>156.285965 606 -402.7305</Position> 4767 4764 <Rotation>0 14.4776783 0</Rotation> 4768 4765 </Header> … … 4835 4832 <Header> 4836 4833 <Flags /> 4837 <Position> 5.104569 AddedXmlTools2 -379.6944</Position>4834 <Position>286.244873 606 -403.317719</Position> 4838 4835 <Rotation>0 356.796539 0</Rotation> 4839 4836 </Header> … … 4906 4903 <Header> 4907 4904 <Flags /> 4908 <Position> 191.788742 AddedXmlTools2 -383.361542</Position>4905 <Position>54.61314 0 -333.546844</Position> 4909 4906 <Rotation>0 136.972717 0</Rotation> 4910 4907 </Header> … … 4977 4974 <Header> 4978 4975 <Flags /> 4979 <Position> 288.8632 AddedXmlTools2 -377.586151</Position>4976 <Position>92.56255 0 -318.030457</Position> 4980 4977 <Rotation>0 136.972717 0</Rotation> 4981 4978 </Header> … … 5048 5045 <Header> 5049 5046 <Flags /> 5050 <Position> 32.003334 AddedXmlTools2 142.236313</Position>5047 <Position>409.398376 0 -305.7882</Position> 5051 5048 <Rotation>0 292.074158 0</Rotation> 5052 5049 </Header> … … 5119 5116 <Header> 5120 5117 <Flags /> 5121 <Position> 74.0541 AddedXmlTools2 158.629745</Position>5118 <Position>289.9704 0 -72.2183456</Position> 5122 5119 <Rotation>0 205.571991 0</Rotation> 5123 5120 </Header> … … 5190 5187 <Header> 5191 5188 <Flags /> 5192 <Position> 3.637498 AddedXmlTools2 89.95713</Position>5189 <Position>173.626175 0 36.94594</Position> 5193 5190 <Rotation>0 134.847549 0</Rotation> 5194 5191 </Header> … … 5261 5258 <Header> 5262 5259 <Flags /> 5263 <Position> -24.60334 AddedXmlTools2 103.25939</Position>5260 <Position>295.288574 60 7.14880371</Position> 5264 5261 <Rotation>0 296.4375 0</Rotation> 5265 5262 </Header> … … 5332 5329 <Header> 5333 5330 <Flags /> 5334 <Position> -49.8743019 AddedXmlTools2 -389.768982</Position>5331 <Position>293.549622 60 -81.6753</Position> 5335 5332 <Rotation>0 329.672516 0</Rotation> 5336 5333 </Header> … … 5403 5400 <Header> 5404 5401 <Flags /> 5405 <Position> 459.521118 AddedXmlTools2 40.6618958</Position>5402 <Position>-22.8269024 60 77.7636261</Position> 5406 5403 <Rotation>0 82.24976 0</Rotation> 5407 5404 </Header> … … 5474 5471 <Header> 5475 5472 <Flags /> 5476 <Position>2 37.516739 AddedXmlTools2 30.885685</Position>5473 <Position>21.0909023 60 -160.9447</Position> 5477 5474 <Rotation>0 97.27289 0</Rotation> 5478 5475 </Header> … … 5545 5542 <Header> 5546 5543 <Flags /> 5547 <Position> 238.657486 AddedXmlTools2 9.82658052</Position>5544 <Position>417.98584 60 -175.537491</Position> 5548 5545 <Rotation>0 270.697144 0</Rotation> 5549 5546 </Header> … … 5616 5613 <Header> 5617 5614 <Flags /> 5618 <Position> 238.093643 AddedXmlTools2 30.9510841</Position>5615 <Position>421.155426 60 -193.092636</Position> 5619 5616 <Rotation>0 270.697144 0</Rotation> 5620 5617 </Header> … … 5687 5684 <Header> 5688 5685 <Flags /> 5689 <Position>3 5.6273518 AddedXmlTools2 -269.1674</Position>5686 <Position>368.3339 120 -335.430664</Position> 5690 5687 <Rotation>0 358.768 0</Rotation> 5691 5688 </Header> … … 5758 5755 <Header> 5759 5756 <Flags /> 5760 <Position> 18.047889 AddedXmlTools2 -303.968872</Position>5757 <Position>45.16015 120 -311.082275</Position> 5761 5758 <Rotation>0 109.107155 0</Rotation> 5762 5759 </Header> … … 5829 5826 <Header> 5830 5827 <Flags /> 5831 <Position> 343.634979 AddedXmlTools2 -372.9142</Position>5828 <Position>-85.43486 120 -284.106232</Position> 5832 5829 <Rotation>0 40.6208 0</Rotation> 5833 5830 </Header> … … 5900 5897 <Header> 5901 5898 <Flags /> 5902 <Position> 444.9334 AddedXmlTools2 -221.2183</Position>5899 <Position>-88.57329 120 17.16457</Position> 5903 5900 <Rotation>0 139.545563 0</Rotation> 5904 5901 </Header> … … 5971 5968 <Header> 5972 5969 <Flags /> 5973 <Position> 206.638962 AddedXmlTools2 0.913823</Position>5970 <Position>-79.8346939 0 70.71216</Position> 5974 5971 <Rotation>0 117.839882 0</Rotation> 5975 5972 </Header> … … 6042 6039 <Header> 6043 6040 <Flags /> 6044 <Position> 142.760071 AddedXmlTools2 257.212509</Position>6041 <Position>51.4552727 681 -283.230347</Position> 6045 6042 <Rotation>0 6.233613 0</Rotation> 6046 6043 </Header> … … 6113 6110 <Header> 6114 6111 <Flags /> 6115 <Position> -27.3426628 AddedXmlTools2 -481.6369</Position>6112 <Position>316.930817 606 -234.495468</Position> 6116 6113 <Rotation>0 167.711685 0</Rotation> 6117 6114 </Header> … … 6184 6181 <Header> 6185 6182 <Flags /> 6186 <Position> 511.63855 AddedXmlTools2 233.189484</Position>6183 <Position>231.037384 120 -150.612183</Position> 6187 6184 <Rotation>0 45.8513031 0</Rotation> 6188 6185 </Header> … … 6255 6252 <Header> 6256 6253 <Flags>Locked</Flags> 6257 <Position> -27.3426628 AddedXmlTools2 -481.6369</Position>6254 <Position>195.1952 120 27.781311</Position> 6258 6255 <Rotation>0 291.8223 0</Rotation> 6259 6256 </Header> … … 6326 6323 <Header> 6327 6324 <Flags /> 6328 <Position> 511.63855 AddedXmlTools2 233.189484</Position>6325 <Position>385.682281 180 151.52861</Position> 6329 6326 <Rotation>0 209.2818 0</Rotation> 6330 6327 </Header> … … 6397 6394 <Header> 6398 6395 <Flags /> 6399 <Position> 237.145248 AddedXmlTools2 -393.65567</Position>6396 <Position>-7.76479864 537 -38.0006142</Position> 6400 6397 <Rotation>0 161.7817 0</Rotation> 6401 6398 </Header> … … 6404 6401 <Class>CopfemA2</Class> 6405 6402 <Name>mbo_femcop</Name> 6406 <Weapon> MyAwesomeOniWeapon</Weapon>6403 <Weapon>w1_tap</Weapon> 6407 6404 <Scripts> 6408 6405 <Spawn /> -
XmlTools2/trunk/main.cpp
r906 r920 12 12 parser.setApplicationDescription("Additional documentation can be found at: http://wiki.oni2.net/XmlTools"); 13 13 14 XmlTools *myXmlTools; 14 15 QString filesWildCard, patchFilesWildCard, forceTargetFilesWildcard; 15 16 QString currentVal, newVal, diffOldNewVal, positions; 17 QString xPathExpression; 16 18 XmlFilter filters; // Filters 19 17 20 bool noBackups=false; 18 19 21 20 22 QCommandLineOption addValuesOption(QStringList() << "a" << "add-values", "Add values to a set of XML elements."); … … 26 28 27 29 QCommandLineOption currentValOption(QStringList() << "c" << "current-val", "Current value(s) [use space as separator].","current-val"); 28 QCommandLineOption newValOption(QStringList() << "n" << "new-val", "New value(s) [use space as separator] ","new-val.");30 QCommandLineOption newValOption(QStringList() << "n" << "new-val", "New value(s) [use space as separator].","new-val"); 29 31 QCommandLineOption diffOldNewValueOption(QStringList() << "d" << "diff-old-new-val", "Difference between old and new value.","diff-old-new-val"); 30 32 QCommandLineOption positionsValueOption(QStringList() << "positions", "Positions [use space as separator] [0-index based].","positions"); … … 37 39 QCommandLineOption attributeNameOption("attribute-name", "Attribute name of <element-name> [used as filter].", "attribute-name"); 38 40 QCommandLineOption attributeValueOption("attribute-value", "Attribute value of <attribute-name> [used as filter].", "attribute-value"); 41 QCommandLineOption xPathExpressionOption(QStringList() << "x" << "xpath-expression", "XPath 1.0 expression to select elements where processing will occur.", "xpath-expression"); 39 42 QCommandLineOption noBackupsOption(QStringList() << "no-backups", "No backups [faster processing]."); 40 43 … … 58 61 parser.addOption(attributeNameOption); 59 62 parser.addOption(attributeValueOption); 63 parser.addOption(xPathExpressionOption); 60 64 parser.addOption(noBackupsOption); 61 65 … … 71 75 } 72 76 73 // Check if the user doesn't want backups (it boost XmlTools peformance, lower disk output)77 // Check if the user doesn't want backups (it boosts XmlTools peformance, lower disk output) 74 78 if(parser.isSet(noBackupsOption)){ 75 79 noBackups=true; … … 94 98 } 95 99 100 if(!parser.isSet(elementNameOption) && !parser.isSet(xPathExpressionOption)){ 101 UtilXmlTools::displayErrorMessage("Parameter Parsing","element-name option or xpath-expression option is required if not using patch-files option."); 102 } 103 else if(parser.isSet(elementNameOption) && parser.isSet(xPathExpressionOption)){ 104 UtilXmlTools::displayErrorMessage("Parameter Parsing","element-name option and xpath-expression options cannot be used simultaneously."); 105 } 106 96 107 // Get element name if available 97 108 if(parser.isSet(elementNameOption)){ … … 99 110 } 100 111 101 if(filters.getElementName()==""){ 102 UtilXmlTools::displayErrorMessage("Parameter Parsing","element-name option is required if not using patch-files option."); 112 // Get xpath expression if available 113 if(parser.isSet(xPathExpressionOption)){ 114 xPathExpression=parser.value(xPathExpressionOption); 103 115 } 104 116 … … 155 167 } 156 168 157 XmlTools myXmlTools(filesWildCard,filters,noBackups); 169 if(parser.isSet(elementNameOption)){ 170 myXmlTools=new XmlTools(filesWildCard,filters,noBackups); 171 } 172 else{ 173 myXmlTools=new XmlTools(filesWildCard,xPathExpression,noBackups); 174 } 158 175 159 176 … … 165 182 } 166 183 167 myXmlTools .addValues(newVal);184 myXmlTools->addValues(newVal); 168 185 } 169 186 else if(parser.isSet(removeValuesOption)){ // Or remove-values option? … … 173 190 } 174 191 175 myXmlTools .removeValues(currentVal);192 myXmlTools->removeValues(currentVal); 176 193 } 177 194 else if(parser.isSet(replaceValueOption)){ // Or replace-value option? … … 181 198 } 182 199 183 myXmlTools .replaceValue(currentVal,newVal);200 myXmlTools->replaceValue(currentVal,newVal); 184 201 } 185 202 else if(parser.isSet(replaceAllValuesOption)){ // Or replace-all-values option? … … 190 207 } 191 208 192 myXmlTools .replaceAll(newVal,positions);209 myXmlTools->replaceAll(newVal,positions); 193 210 } 194 211 else if(parser.isSet(updateElementsOption)){ // Or update-elements option? … … 199 216 } 200 217 201 myXmlTools .updateElements(diffOldNewVal);218 myXmlTools->updateElements(diffOldNewVal); 202 219 } 203 220 else if(parser.isSet(invertElementsOption)){ // Or invert-elements option? 204 myXmlTools .invertElements();221 myXmlTools->invertElements(); 205 222 } 206 223 else{ … … 209 226 } 210 227 228 //delete myXmlTools; 211 229 //std::cout << "Started" << std::endl; 212 230 -
XmlTools2/trunk/readme.txt
r906 r920 35 35 36 36 -Remove XML from existing files (patch only). 37 38 -Select elements using element name, parent element name, attribute name/value and XPath 1.0. 37 39 38 40 -Powerful custom XML editing using javascript (for what you can't do with native operations) (patch only). … … 75 77 REMOVE -> REMOVE_NODE 76 78 CUSTOMCODE -> CUSTOM_CODE 79 -Added option to select xml elements by attribute name and value 80 -Added option to select xml elements by XPath 1.0 (should reduce the need of javascript) -
XmlTools2/trunk/util.cpp
r906 r920 3 3 namespace GlobalVars{ 4 4 QString AppName="XmlTools"; 5 #ifdef Q_OS_WIN 6 QString AppExecutable=AppName+".exe"; 7 #else 8 QString AppExecutable="./"+AppName; // Mac OS needs unix like executing 9 #endif 5 10 QString AppVersion="2.0"; 6 11 } -
XmlTools2/trunk/util.h
r906 r920 10 10 namespace GlobalVars{ 11 11 extern QString AppName; 12 extern QString AppExecutable; 12 13 extern QString AppVersion; 13 14 } -
XmlTools2/trunk/utilxmltools.cpp
r906 r920 55 55 } 56 56 57 void getAllXpathElements(const QString &xPathExpression, pugi::xml_document &doc, QList<pugi::xml_node> &result){ 58 59 pugi::xpath_node_set selectedNodes; 60 pugi::xpath_node node; 61 62 try 63 { 64 selectedNodes = doc.select_nodes(xPathExpression.toLatin1().constData()); 65 } 66 67 catch (const pugi::xpath_exception& e) 68 { 69 displayErrorMessage("XPath element selection","Selection of elements using the XPathExpression: '" + xPathExpression + "' failed:\n" + e.what()); 70 } 71 72 for (pugi::xpath_node_set::const_iterator currNode = selectedNodes.begin(); currNode != selectedNodes.end(); ++currNode) 73 { 74 node = *currNode; 75 if(node){ // if node != null 76 result << node.node(); 77 } 78 } 79 80 if(result.isEmpty()){ 81 result << pugi::xml_node(); // add an empty node if none found 82 } 83 84 } 85 86 pugi::xml_node getFirstXpathElement(const QString &xPathExpression, pugi::xml_document &doc){ 87 pugi::xpath_node selectedNode; 88 89 try 90 { 91 selectedNode = doc.select_single_node(xPathExpression.toLatin1().constData()); 92 } 93 94 catch (const pugi::xpath_exception& e) 95 { 96 displayErrorMessage("XPath element selection","Selection of element using the XPathExpression: '" + xPathExpression + "' failed:\n" + e.what()); 97 } 98 99 return selectedNode.node(); 100 } 101 57 102 void getAllNamedElements(pugi::xml_node &node, QList<pugi::xml_node> &result, XmlFilter &filters){ 58 103 for (pugi::xml_node_iterator currNode = node.begin(); currNode != node.end(); ++currNode) … … 70 115 } 71 116 72 pugi::xml_node getFirstNamedElement s(pugi::xml_node &node, XmlFilter &filters){117 pugi::xml_node getFirstNamedElement(pugi::xml_node &node, XmlFilter &filters){ 73 118 74 119 pugi::xml_node foundNode; … … 82 127 } 83 128 84 foundNode=getFirstNamedElement s(*currNode,filters);129 foundNode=getFirstNamedElement(*currNode,filters); 85 130 86 131 if(foundNode.type()!=pugi::node_null){ -
XmlTools2/trunk/utilxmltools.h
r906 r920 14 14 void backupFile(const QString &file); 15 15 void getAllNamedElements(pugi::xml_node &node, QList<pugi::xml_node> &result, XmlFilter &filters); 16 void getAllXpathElements(const QString &xPathExpression, pugi::xml_document &doc, QList<pugi::xml_node> &result); 16 17 void displaySuccessMessage(const int numberOperations, const QString &operation); 17 18 void displayErrorMessage(const QString& operation, const QString &message, bool exitProgram=true); 18 pugi::xml_node getFirstNamedElements(pugi::xml_node &node, XmlFilter &filters); 19 pugi::xml_node getFirstNamedElement(pugi::xml_node &node, XmlFilter &filters); 20 pugi::xml_node getFirstXpathElement(const QString &xPathExpression, pugi::xml_document &doc); 19 21 20 22 //// inline functions -
XmlTools2/trunk/xmlfilter.cpp
r906 r920 46 46 this->attributeValue=attributeValue; 47 47 } 48 49 // Clears filter 50 void XmlFilter::clear(){ 51 this->elementName.clear(); 52 this->parentElementName.clear(); 53 this->attributeName.clear(); 54 this->attributeValue.clear(); 55 } -
XmlTools2/trunk/xmlfilter.h
r906 r920 21 21 void setAttributeName(QString attributeName); 22 22 void setAttributeValue(QString attributeValue); 23 24 void clear(); 23 25 private: 24 26 QString elementName; -
XmlTools2/trunk/xmlpatch.cpp
r910 r920 44 44 } 45 45 46 void XmlPatch:: addToOperation(const QString &xmlString, XmlFilter &filters, const QString &filesWildcard){46 void XmlPatch::insertNodesOperation(const QString &xmlString, XmlFilter &filters, const QString &xPathExpression, const QString &filesWildcard){ 47 47 48 48 QStringList filesToProcess; 49 pugi::xml_node nodeToInsertion;49 QList<pugi::xml_node> nodesToInsertion; 50 50 pugi::xml_document newNode; 51 51 pugi::xml_parse_result result; … … 54 54 55 55 if(filesToProcess.isEmpty()){ 56 UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODE ","No XML files were found for the wildcard: "+filesWildcard);56 UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODES","No XML files were found for the wildcard: "+filesWildcard); 57 57 } 58 58 … … 60 60 61 61 if(result.status!=pugi::status_ok){ 62 UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODE ", "The xml node to insert is invalid.\n" + Util::toQString(result.description()));62 UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODES", "The xml node to insert is invalid.\n" + Util::toQString(result.description())); 63 63 } 64 64 … … 66 66 for(int i=0; i<filesToProcess.size(); i++){ 67 67 68 UtilXmlTools::loadXmlFile(filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,"@ADD_INSIDE_NODE"); 69 70 nodeToInsertion=UtilXmlTools::getFirstNamedElements(this->rootNode,filters); 71 72 if(nodeToInsertion.type()==pugi::node_null){ 68 UtilXmlTools::loadXmlFile(filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,"@ADD_INSIDE_NODES"); 69 70 // Check how the element will be fetched via element name or xpath expression 71 if(xPathExpression.isEmpty()){ 72 UtilXmlTools::getAllNamedElements(this->rootNode,nodesToInsertion,filters); 73 } 74 else{ 75 UtilXmlTools::getAllXpathElements(xPathExpression,this->document,nodesToInsertion); 76 } 77 78 if(nodesToInsertion[0].type()==pugi::node_null){ 73 79 74 80 QString errMessage; 75 81 76 errMessage = "It wasn't found a node with a ElementName: '" + filters.getElementName() + "'"; 77 if(filters.getParentElementName()!=""){ 78 errMessage += " and a ParentElementName: '" + filters.getParentElementName() + "'"; 79 } 80 if(filters.getAttributeName()!=""){ 81 errMessage += " and an AttributeName: '" + filters.getAttributeName() + "' and an AttributeValue: '" + filters.getAttributeValue() + "'"; 82 } 83 84 UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODE",errMessage); 85 } 86 87 nodeToInsertion.prepend_copy(newNode.first_child()); // append the new node 88 89 90 UtilXmlTools::saveXmlFile(filesToProcess[i],this->document, "@ADD_INSIDE_NODE"); 91 } 92 93 UtilXmlTools::displaySuccessMessage(filesToProcess.size(),"@ADD_INSIDE_NODE"); 94 } 95 96 void XmlPatch::removeNodeOperation(XmlFilter &filters, const QString &filesWildcard){ 82 if(xPathExpression.isEmpty()){ 83 errMessage = "It wasn't found any node with a ElementName: '" + filters.getElementName() + "'"; 84 if(filters.getParentElementName()!=""){ 85 errMessage += " and a ParentElementName: '" + filters.getParentElementName() + "'"; 86 } 87 if(filters.getAttributeName()!=""){ 88 errMessage += " and an AttributeName: '" + filters.getAttributeName() + "' and an AttributeValue: '" + filters.getAttributeValue() + "'"; 89 } 90 } 91 else{ 92 errMessage = "It wasn't found any node with a XPathExpression: '" + xPathExpression + "'"; 93 } 94 95 UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODES",errMessage); 96 } 97 98 for(int j=0; j<nodesToInsertion.size(); j++){ 99 nodesToInsertion[j].prepend_copy(newNode.first_child()); // append the new node 100 } 101 102 103 UtilXmlTools::saveXmlFile(filesToProcess[i],this->document, "@ADD_INSIDE_NODES"); 104 } 105 106 UtilXmlTools::displaySuccessMessage(filesToProcess.size(),"@ADD_INSIDE_NODES"); 107 } 108 109 void XmlPatch::removeNodesOperation(XmlFilter &filters, const QString &xPathExpression, const QString &filesWildcard){ 97 110 98 111 QStringList filesToProcess; 99 112 100 pugi::xml_node nodeToDeletion;113 QList<pugi::xml_node> nodesToDeletion; 101 114 102 115 filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard); 103 116 104 117 if(filesToProcess.isEmpty()){ 105 UtilXmlTools::displayErrorMessage("@REMOVE_NODE ","No XML files were found for the wildcard: "+filesWildcard);118 UtilXmlTools::displayErrorMessage("@REMOVE_NODES","No XML files were found for the wildcard: "+filesWildcard); 106 119 } 107 120 … … 109 122 for(int i=0; i<filesToProcess.size(); i++){ 110 123 111 UtilXmlTools::loadXmlFile(filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,"@REMOVE_NODE"); 112 113 nodeToDeletion=UtilXmlTools::getFirstNamedElements(this->rootNode,filters); 114 115 if(nodeToDeletion.type()==pugi::node_null){ 124 UtilXmlTools::loadXmlFile(filesToProcess[i],this->document,this->rootNode,this->backupsEnabled,"@REMOVE_NODES"); 125 126 // Check how the element will be fetched via element name or xpath expression 127 if(xPathExpression.isEmpty()){ 128 UtilXmlTools::getAllNamedElements(this->rootNode,nodesToDeletion,filters); 129 } 130 else{ 131 UtilXmlTools::getAllXpathElements(xPathExpression,this->document,nodesToDeletion); 132 } 133 134 if(nodesToDeletion[0].type()==pugi::node_null){ 135 116 136 QString errMessage; 117 137 118 errMessage = "It wasn't found a node with a ElementName: '" + filters.getElementName() + "'"; 119 if(filters.getParentElementName()!=""){ 120 errMessage += " and a ParentElementName: '" + filters.getParentElementName() + "'"; 121 } 122 if(filters.getAttributeName()!=""){ 123 errMessage += " and an AttributeName: '" + filters.getAttributeName() + "' and an AttributeValue: '" + filters.getAttributeValue() + "'"; 124 } 125 126 UtilXmlTools::displayErrorMessage("@REMOVE_NODE",errMessage); 127 } 128 129 if(!nodeToDeletion.parent().remove_child(nodeToDeletion)){ // remove the node 130 131 QString errMessage; 132 133 errMessage = "Couldn't remove the node with Element '" + filters.getElementName() + "'"; 134 135 if(filters.getParentElementName()!=""){ 136 errMessage += " and a ParentElement: '" + filters.getParentElementName() + "'"; 137 } 138 139 UtilXmlTools::displayErrorMessage("@REMOVE_NODE",errMessage); 140 } 141 142 UtilXmlTools::saveXmlFile(filesToProcess[i],this->document, "@REMOVE_NODE"); 143 } 144 145 UtilXmlTools::displaySuccessMessage(filesToProcess.size(), "@REMOVE_NODE"); 138 if(xPathExpression.isEmpty()){ 139 errMessage = "It wasn't found any node with a ElementName: '" + filters.getElementName() + "'"; 140 if(filters.getParentElementName()!=""){ 141 errMessage += " and a ParentElementName: '" + filters.getParentElementName() + "'"; 142 } 143 if(filters.getAttributeName()!=""){ 144 errMessage += " and an AttributeName: '" + filters.getAttributeName() + "' and an AttributeValue: '" + filters.getAttributeValue() + "'"; 145 } 146 } 147 else{ 148 errMessage = "It wasn't found any node with a XPathExpression: '" + xPathExpression + "'"; 149 } 150 151 UtilXmlTools::displayErrorMessage("@REMOVE_NODES",errMessage); 152 } 153 154 // Delete all the specified nodes 155 for(int j=0; j<nodesToDeletion.size(); j++){ 156 if(!nodesToDeletion[j].parent().remove_child(nodesToDeletion[j])){ // remove the node 157 158 QString errMessage; 159 if(xPathExpression.isEmpty()){ 160 errMessage = "Couldn't remove the node with Element '" + filters.getElementName() + "'"; 161 162 if(filters.getParentElementName()!=""){ 163 errMessage += " and a ParentElement: '" + filters.getParentElementName() + "'"; 164 } 165 } 166 else{ 167 errMessage = "Couldn't remove the node with the XPathExpression '" + xPathExpression + "'"; 168 } 169 170 UtilXmlTools::displayErrorMessage("@REMOVE_NODES",errMessage); 171 } 172 } 173 174 UtilXmlTools::saveXmlFile(filesToProcess[i],this->document, "@REMOVE_NODES"); 175 } 176 177 UtilXmlTools::displaySuccessMessage(filesToProcess.size(), "@REMOVE_NODES"); 146 178 } 147 179 … … 152 184 153 185 // Avoid infinite fork loops 154 if(commandString.contains(" -p") || commandString.contains("--patch-files")){186 if(commandString.contains(" -p ") || commandString.contains(" --patch-files ")){ 155 187 UtilXmlTools::displayErrorMessage("@COMMAND","Use of --patch-files option is not allowed inside a patch file"); 156 188 } 157 189 158 newXmlToolsInstance.start(GlobalVars::App Name + " " + commandString);190 newXmlToolsInstance.start(GlobalVars::AppExecutable + " " + commandString); 159 191 newXmlToolsInstance.waitForFinished(-1); // wait for new instance to finish 160 192 … … 166 198 } 167 199 168 std::cout << "@COMMAND patch operation output:\n" << resultOutput.toLatin1().constData() << std::endl; 200 std::cout << "@COMMAND patch operation output:\n" 201 << "########################################################################\n" 202 << resultOutput.toLatin1().constData() 203 << "########################################################################" 204 << std::endl; 169 205 170 206 UtilXmlTools::displaySuccessMessage(1,"@COMMAND"); … … 289 325 QString line, filesWildcard; 290 326 QString xmlToInsert, command, jsCode; 327 QString xPathExpression; 291 328 XmlFilter filters; 292 329 … … 298 335 continue; 299 336 } 300 else if(line.startsWith("@ADD_INSIDE_NODE")){ 337 else if(line.startsWith("@ADD_INSIDE_NODES")){ 338 xPathExpression=getPatchParameterValue(line,"XPathExpression"); 301 339 filters.setElementName(getPatchParameterValue(line,"ElementName")); 302 340 filters.setParentElementName(getPatchParameterValue(line,"ParentElementName")); … … 311 349 } 312 350 313 // Check attribute filters 351 // Check options 352 if(xPathExpression.isEmpty() && filters.getElementName().isEmpty()){ 353 UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODES","ElementName option or XPathExpression option is required."); 354 } 355 else if(!xPathExpression.isEmpty() && !filters.getElementName().isEmpty()){ 356 UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODES","ElementName option and XPathExpression options cannot be used simultaneously."); 357 } 314 358 if(filters.getAttributeName()!="" && filters.getAttributeValue()==""){ 315 UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODE ","attribute-value option is required if using attribute-name option.");359 UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODES","AttributeValue option is required if using AttributeName option."); 316 360 } 317 361 318 362 if(filters.getAttributeValue()!="" && filters.getAttributeName()==""){ 319 UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODE ","attribute-name option is required if using attribute-value option.");363 UtilXmlTools::displayErrorMessage("@ADD_INSIDE_NODES","AttributeName option is required if using AttributeValue option."); 320 364 } 321 365 … … 328 372 } 329 373 330 addToOperation(xmlToInsert,filters,filesWildcard); 331 332 } 333 else if(line.startsWith("@REMOVE_NODE")){ 334 374 insertNodesOperation(xmlToInsert,filters,xPathExpression,filesWildcard); 375 376 xmlToInsert.clear(); 377 filters.clear(); 378 xPathExpression.clear(); 379 filesWildcard.clear(); 380 } 381 else if(line.startsWith("@REMOVE_NODES")){ 382 383 xPathExpression=getPatchParameterValue(line,"XPathExpression"); 335 384 filters.setElementName(getPatchParameterValue(line,"ElementName")); 336 385 filters.setParentElementName(getPatchParameterValue(line,"ParentElementName")); … … 345 394 } 346 395 347 // Check attribute filters 396 // Check options 397 if(xPathExpression.isEmpty() && filters.getElementName().isEmpty()){ 398 UtilXmlTools::displayErrorMessage("@REMOVE_NODES","ElementName option or XPathExpression option is required."); 399 } 400 else if(!xPathExpression.isEmpty() && !filters.getElementName().isEmpty()){ 401 UtilXmlTools::displayErrorMessage("@REMOVE_NODES","ElementName option and XPathExpression options cannot be used simultaneously."); 402 } 403 348 404 if(filters.getAttributeName()!="" && filters.getAttributeValue()==""){ 349 UtilXmlTools::displayErrorMessage("@REMOVE_NODE ","attribute-value option is required if using attribute-name option.");405 UtilXmlTools::displayErrorMessage("@REMOVE_NODES","AttributeValue option is required if using AttributeName option."); 350 406 } 351 407 352 408 if(filters.getAttributeValue()!="" && filters.getAttributeName()==""){ 353 UtilXmlTools::displayErrorMessage("@REMOVE_NODE","attribute-name option is required if using attribute-value option."); 354 } 355 356 removeNodeOperation(filters,filesWildcard); 357 409 UtilXmlTools::displayErrorMessage("@REMOVE_NODES","AttributeName option is required if using AttributeValue option."); 410 } 411 412 removeNodesOperation(filters,xPathExpression,filesWildcard); 413 414 filters.clear(); 415 xPathExpression.clear(); 416 filesWildcard.clear(); 358 417 } 359 418 else if(line.startsWith("@COMMAND")){ 360 419 361 command=getPatchParameterValue(line,""); 420 command=getPatchParameterValue(line,"Arguments"); 421 422 command.replace("'","\""); //replace apostrophe by quotes, to avoid problems 362 423 363 424 executeCommandOperation(command); 425 426 command.clear(); 364 427 } 365 428 else if(line.startsWith("@CUSTOM_CODE")){ … … 382 445 383 446 executeCustomCommandOperation(jsCode,filesWildcard); 447 448 jsCode.clear(); 449 filesWildcard.clear(); 384 450 } 385 451 } … … 390 456 int startValueIdx, endValueIdx; 391 457 392 parameter +=" "; // Parameters include a space beforeit's value.458 parameter=" "+parameter+" "; // Parameters include a space before and after it's value. 393 459 394 460 if(!line.contains(parameter)){ 395 if(parameter=="ParentElementName " || parameter=="AttributeName " || parameter=="AttributeValue "){ 461 if(parameter==" ParentElementName " || parameter==" AttributeName " || parameter==" AttributeValue " 462 || parameter==" ElementName " || parameter==" XPathExpression "){ 396 463 return ""; // not mandatory 397 464 } -
XmlTools2/trunk/xmlpatch.h
r906 r920 16 16 bool backupsEnabled; 17 17 QString getPatchParameterValue(const QString& line, QString parameter); 18 void addToOperation(const QString &xmlString, XmlFilter &filters, const QString &filesWildcard="");19 void removeNode Operation(XmlFilter &filters, const QString &filesWildcard="");18 void insertNodesOperation(const QString &xmlString, XmlFilter &filters, const QString &xPathExpression, const QString &filesWildcard=""); 19 void removeNodesOperation(XmlFilter &filters, const QString &xPathExpression, const QString &filesWildcard=""); 20 20 void executeCommandOperation(const QString &commandString); 21 21 void executeCustomCommandOperation(const QString &jsString, const QString &filesWildcard=""); -
XmlTools2/trunk/xmltools.cpp
r910 r920 1 1 #include "xmltools.h" 2 2 3 // Filters constructor 3 4 XmlTools::XmlTools(QString filesWildcard, XmlFilter filter, bool noBackups) 4 5 { … … 12 13 } 13 14 15 // XPath constructor 16 XmlTools::XmlTools(QString filesWildcard, QString xPathExpression, bool noBackups) 17 { 18 this->filesToProcess=UtilXmlTools::getAllXmlFilesByWildcard(filesWildcard); 19 this->xPathExpression=xPathExpression; 20 this->backupsEnabled=!noBackups; 21 } 22 14 23 // Adds new values to an element 15 24 void XmlTools::addValues(QString newValues){ … … 24 33 25 34 newValuesList=Util::qStringListFromSpacedString(newValues); 26 UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); 35 36 // Check how the elements will be fetched via element name or xpath expression 37 if(this->xPathExpression==""){ 38 UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); 39 } 40 else{ 41 UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); 42 } 27 43 28 44 for(int j=0; j<elements.size(); j++){ … … 57 73 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, "remove-values"); 58 74 59 UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); 75 // Check how the elements will be fetched via element name or xpath expression 76 if(this->xPathExpression==""){ 77 UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); 78 } 79 else{ 80 UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); 81 } 60 82 61 83 valuesToRemoveList=Util::qStringListFromSpacedString(valuesToRemove); … … 98 120 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, "replace-value"); 99 121 100 UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); 122 // Check how the elements will be fetched via element name or xpath expression 123 if(this->xPathExpression==""){ 124 UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); 125 } 126 else{ 127 UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); 128 } 101 129 102 130 for(int j=0; j<elements.size(); j++){ … … 132 160 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, "replace-all"); 133 161 134 UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); 162 // Check how the elements will be fetched via element name or xpath expression 163 if(this->xPathExpression==""){ 164 UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); 165 } 166 else{ 167 UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); 168 } 135 169 136 170 … … 166 200 UtilXmlTools::loadXmlFile(this->filesToProcess[i],this->document,this->rootNode,this->backupsEnabled, "update-elements"); 167 201 168 UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); 202 // Check how the elements will be fetched via element name or xpath expression 203 if(this->xPathExpression==""){ 204 UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); 205 } 206 else{ 207 UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); 208 } 169 209 170 210 … … 207 247 QStringList invertedElements; //Inverting the element order 208 248 209 UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); 249 // Check how the elements will be fetched via element name or xpath expression 250 if(this->xPathExpression==""){ 251 UtilXmlTools::getAllNamedElements(this->rootNode,elements,this->filters); 252 } 253 else{ 254 UtilXmlTools::getAllXpathElements(this->xPathExpression,this->document,elements); 255 } 210 256 211 257 // Read all elements and save to the list -
XmlTools2/trunk/xmltools.h
r906 r920 26 26 public: 27 27 XmlTools(QString filesWildcard, XmlFilter filter, bool noBackups); 28 XmlTools(QString filesWildcard, QString xPathExpression, bool noBackups); 28 29 void addValues(QString newValues); 29 30 void removeValues(QString valuesToRemove); … … 37 38 pugi::xml_node rootNode; 38 39 QStringList filesToProcess; 40 QString xPathExpression; 39 41 XmlFilter filters; 40 42 bool backupsEnabled;
Note:
See TracChangeset
for help on using the changeset viewer.