# Script for XML File Edit Only Executes In Designer

**URL:** <https://forum.inductiveautomation.com/t/script-for-xml-file-edit-only-executes-in-designer/33784>\
**Category:** Ignition\
**Created:** [April 8, 2020, 2:25pm UTC](https://forum.inductiveautomation.com/t/script-for-xml-file-edit-only-executes-in-designer/33784 "2020-04-08T14:25:50Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![byutz](https://avatars.discourse-cdn.com/v4/letter/b/b38774/32.png) [@byutz](https://forum.inductiveautomation.com/u/byutz)\
**Post date:** [April 8, 2020, 2:25pm UTC](https://forum.inductiveautomation.com/t/script-for-xml-file-edit-only-executes-in-designer/33784/1 "2020-04-08T14:25:50Z")

</div>

Hello,

I have a script that executes off of a button click that works flawlessly from the designer in Test mode. However, once I launch the project and try to run it, it fails. The script opens an xml file, edits a few of the entries, and then saves it. I currently have it trying to read and update the file on my desktop to eliminate any network permission issues. The project is being ran off of my profile, which has full permissions. I removed all of the code that actually does any of the editing and saving, and it still gets the error, which leads me to believe its some sort of issue importing the xml library. Does anyone have any suggestions?

I removed a few lines from the code so it would display better on here, but the error is always on the line with “ET.parse” .

Code:

```auto
import xml.etree.ElementTree as ET
	try:
		#get selected filler
		fillerValue = event.source.parent.getComponent('FillerList').selectedValue
		MOValue = event.source.parent.getComponent('txtMO').text
		ProdIDValue = str(event.source.parent.getComponent('txtProdID').intValue)
		if fillerValue == 1 or fillerValue == 2:
			if fillerValue == 1:
				fillerText = 'FILLER_1'
				fileSavePath = r"C:\Users\BYutz\Desktop\prod_perf_3.xml"
			else:
				fillerText = 'FILLER_2'
				fileSavePath = r"C:\Users\BYutz\Desktop\prod_perf_47.xml"
			
			#location of the sample xml to edit, it will save as a completely new file
			tree = ET.parse(r"C:\Users\BYutz\Desktop\doNotDelete.xml")

```

Error:

```auto
Traceback (most recent call last):
  File "<event:actionPerformed>", line 19, in <module>
  File "<event:actionPerformed>", line 19, in <module>
  File "C:\Users\BYutz\.ignition\cache\gwcomo-svr-eng_8088\C1\pylib\xml\etree\ElementTree.py", line 1184, in parse
    tree.parse(source, parser)
  File "C:\Users\BYutz\.ignition\cache\gwcomo-svr-eng_8088\C1\pylib\xml\etree\ElementTree.py", line 651, in parse
    parser = XMLParser(target=TreeBuilder())
  File "C:\Users\BYutz\.ignition\cache\gwcomo-svr-eng_8088\C1\pylib\xml\etree\ElementTree.py", line 1480, in __init__
    parser = expat.ParserCreate(encoding, "}")
  File "C:\Users\BYutz\.ignition\cache\gwcomo-svr-eng_8088\C1\pylib\xml\parsers\expat.py", line 59, in ParserCreate
    return XMLParser(encoding, namespace_separator)
  File "C:\Users\BYutz\.ignition\cache\gwcomo-svr-eng_8088\C1\pylib\xml\parsers\expat.py", line 91, in __init__
    self._reader = XMLReaderFactory.createXMLReader(_xerces_parser_name)
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser

org.xml.sax.SAXException: org.xml.sax.SAXException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser

	caused by org.xml.sax.SAXException: SAX2 driver class org.apache.xerces.parsers.SAXParser not found
java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser

	caused by ClassNotFoundException: org.apache.xerces.parsers.SAXParser

Ignition v8.0.7 (b2019122014)
Java: Azul Systems, Inc. 11.0.5

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 8, 2020, 2:42pm UTC](https://forum.inductiveautomation.com/t/script-for-xml-file-edit-only-executes-in-designer/33784/2 "2020-04-08T14:42:11Z")

</div>

Ignition’s client environment simply isn’t including that Apache jar. Consider using Java’s own XML processing classes–that’s almost certainly present.

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [April 8, 2020, 3:18pm UTC](https://forum.inductiveautomation.com/t/script-for-xml-file-edit-only-executes-in-designer/33784/3 "2020-04-08T15:18:19Z")

</div>

Can you post the rest of the code?  
We use the same classes and it works fine in the client and designer.

```auto
from __future__ import with_statement
import xml.etree.ElementTree as ET
import os, sys, codecs
import system
import re
getXML = system.file.openFile('.XML',"")
path = getXML
tree = ET.parse(path)
root = tree.getroot() 
context = root.getiterator(tag='DataType')

```

---

<div class="post-metadata">

**Author:** ![byutz](https://avatars.discourse-cdn.com/v4/letter/b/b38774/32.png) [@byutz](https://forum.inductiveautomation.com/u/byutz)\
**Post date:** [April 8, 2020, 3:33pm UTC](https://forum.inductiveautomation.com/t/script-for-xml-file-edit-only-executes-in-designer/33784/4 "2020-04-08T15:33:04Z")

</div>

Here it is.

```auto
import xml.etree.ElementTree as ET
if system.gui.confirm(u'Are you sure you want to update CoLOS?', 'Confirm'):
	try:
		#get selected filler
		fillerValue = event.source.parent.getComponent('FillerList').selectedValue
		MOValue = event.source.parent.getComponent('txtMO').text
		ProdIDValue = str(event.source.parent.getComponent('txtProdID').intValue)
		if fillerValue == 1 or fillerValue == 2:
			if fillerValue == 1:
				fillerText = 'FILLER_1'
				#fileSavePath = r"\\como-svr-colos\data\Import\o crap copies\test_prod_perf_3.xml"#r signifies a filepath so it will process properly
				fileSavePath = r"C:\Users\BYutz\Desktop\prod_perf_3.xml"
			else:
				fillerText = 'FILLER_2'
				fileSavePath = r"C:\Users\BYutz\Desktop\prod_perf_47.xml"
			
			#location of the sample xml to edit, it will save as a completely new file
			#tree = ET.parse(r"\\como-svr-eng\DocSample\doNotDelete.xml")
			tree = ET.parse(r"C:\Users\BYutz\Desktop\doNotDelete.xml")
			a = tree.find('ProductionResponse')
			b = a.find('SegmentResponse')
			
			#alter productID
			prodID = b.find('ID')
			prodID.text = ProdIDValue
			
			#alter MO
			moNumber = b.find('MONumber')
			moNumber.text = MOValue
			
			#get and alter filler number
			c = b.find('EquipmentActual')
			filler = c.find('EquipmentID')
			filler.text = fillerText
			
			#save the file
			tree.write(fileSavePath)
			system.gui.warningBox("Success!")
		else:
			system.gui.warningBox("Please select a filler.")
	except Exception, value:
		system.gui.errorBox(str(value.getCause()))

```

---

<div class="post-metadata">

**Author:** ![MMaynard](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/mmaynard/32/3366_2.png) [@MMaynard](https://forum.inductiveautomation.com/u/MMaynard)\
**Post date:** [April 8, 2020, 4:27pm UTC](https://forum.inductiveautomation.com/t/script-for-xml-file-edit-only-executes-in-designer/33784/5 "2020-04-08T16:27:19Z")

</div>

Can you try to set the path using the file open code?  
Or double up on all of your backslashes in the path.

```auto
tree = ET.parse(r"C:\\Users\\BYutz\\Desktop\\doNotDelete.xml")

```

---

<div class="post-metadata">

**Author:** ![byutz](https://avatars.discourse-cdn.com/v4/letter/b/b38774/32.png) [@byutz](https://forum.inductiveautomation.com/u/byutz)\
**Post date:** [April 8, 2020, 6:17pm UTC](https://forum.inductiveautomation.com/t/script-for-xml-file-edit-only-executes-in-designer/33784/6 "2020-04-08T18:17:23Z")

</div>

I tried both, and I get the same error. Thanks for the suggestion though! I feel like this has to be a bug. I am on 8.0.7 and will be upgrading as soon as we get some downtime.

---

<div class="post-metadata">

**Author:** ![byutz](https://avatars.discourse-cdn.com/v4/letter/b/b38774/32.png) [@byutz](https://forum.inductiveautomation.com/u/byutz)\
**Post date:** [April 10, 2020, 1:29pm UTC](https://forum.inductiveautomation.com/t/script-for-xml-file-edit-only-executes-in-designer/33784/7 "2020-04-10T13:29:44Z")

</div>

Is there are reason its not included? Or is it a bug? It seems odd a feature would be set up to work in the designer but not in the client environment.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [April 10, 2020, 3:27pm UTC](https://forum.inductiveautomation.com/t/script-for-xml-file-edit-only-executes-in-designer/33784/8 "2020-04-10T15:27:38Z")

</div>

Not terribly odd. There’s lots of designer-UI stuff that doesn’t get loaded in the client, either. I ran into some of that with the Batik SVG libraries when building my SVG component.

This highlights the value of my general approach in jython: If there’s a java standard library that provides functionality that you need, use it instead of the python standard library. Even if both are available.

---

<div class="post-metadata">

**Author:** ![paula.talley](https://avatars.discourse-cdn.com/v4/letter/p/50afbb/32.png) [@paula.talley](https://forum.inductiveautomation.com/u/paula.talley)\
**Post date:** [June 9, 2020, 4:59pm UTC](https://forum.inductiveautomation.com/t/script-for-xml-file-edit-only-executes-in-designer/33784/9 "2020-06-09T16:59:34Z")

</div>

I didn’t have the choice of switching to Java classes because I am using a third party library that is in turn using the SAXParser. But, I got around it by moving the code to a Gateway script. Of course, I am parsing a really big Excel file, so it makes sense to do it on the Gateway anyway. May be overkill for a simple XML parse.

---

<div class="post-metadata">

**Author:** ![PJK\_AS](https://avatars.discourse-cdn.com/v4/letter/p/838e76/32.png) [@PJK\_AS](https://forum.inductiveautomation.com/u/PJK_AS)\
**Post date:** [December 21, 2020, 7:45pm UTC](https://forum.inductiveautomation.com/t/script-for-xml-file-edit-only-executes-in-designer/33784/10 "2020-12-21T19:45:03Z")

</div>

Hello,

Just wondering - were you ever able to come up with a solution/work-around for this issue that still utilized the same library?

I am currently dealing with almost the exact same identical problem as you had listed and happen to be getting the same import error - java.lang.ClassNotFoundException: org.apache.xerces.parsers.SAXParser

Works flawlessly in the designer, but fails in the project once it is opened.

Thanks

---

<div class="post-metadata">

**Author:** ![byutz](https://avatars.discourse-cdn.com/v4/letter/b/b38774/32.png) [@byutz](https://forum.inductiveautomation.com/u/byutz)\
**Post date:** [December 21, 2020, 10:08pm UTC](https://forum.inductiveautomation.com/t/script-for-xml-file-edit-only-executes-in-designer/33784/11 "2020-12-21T22:08:21Z")

</div>

Sorry, I was not able to. I started to try using a java library, but was unable to get enough time to complete, not to mention frustrated that all my previous work was for nothing 🙂 . I just run the utility in the designer when I need it.
