Jump to content

Can you spot what's wrong with this result XML?


Recommended Posts

Hi guys,

 

I've been trying to return some results from a Python-based workflow. While it kind of works, when selecting one of the items, the corresponding file doesn't open. What am I doing wrong?

<?xml version="1.0"?>
<items>
<item arg="/Users/apopescu/Dropbox/ka/nvall/qq-Git tags.md" uid="Gittags" valid="yes" type="file">
	<title>Git tags:</title>
	<subtitle>Find the closest tag related to the specific commit:</subtitle>
</item>
</items>

Thanks a lot,

 

:- a

Link to comment

Just a guess from the code, but you may need to escape your file path argument. That is, the space in the file name doesn't look properly encoded in the xml. So, when you select that item, you are looking for "/Users/apopescu/Dropbox/ka/nvall/qq-Git", which obviously doesn't exist.

Link to comment

It's possible that you've got the escaping wrong in your Open File action. Are you sure you've selected "Escape spaces"?

 

An important tip, however: you should not be generating the XML the way you're doing (using string formatting).

 

Use one of the XML libraries built into Python. xml.etree.ElementTree is the common choice.

 

This will output the XML you posted, and will not break if a file path has <, > or & in it (which your script absolutely will):


from xml.etree import ElementTree as ET

root = ET.Element('items')
item = ET.SubElement(root, 'item',
                     {'arg': u'/Users/apopescu/Dropbox/ka/nvall/qq-Git tags.md',
                      'uid': u'Gittags', 'valid': 'yes', 'type': 'file'})
ET.SubElement(item, 'title').text = u'Git tags:'
ET.SubElement(item, 'subtitle').text = u'Find the closest tag related to the specific commit:'

print ET.tostring(root).encode('utf-8')

Note that I've preceded every string that could contain non-ASCII characters with u, to tell Python that it's Unicode, not ASCII.

Link to comment

Hi guys,

 

I've been trying to return some results from a Python-based workflow. While it kind of works, when selecting one of the items, the corresponding file doesn't open. What am I doing wrong?

<?xml version="1.0"?>
<items>
<item arg="/Users/apopescu/Dropbox/ka/nvall/qq-Git tags.md" uid="Gittags" valid="yes" type="file">
	<title>Git tags:</title>
	<subtitle>Find the closest tag related to the specific commit:</subtitle>
</item>
</items>

Thanks a lot,

 

:- a

 

This XML is valid. A good test for things like this is to create a simple workflow, add a script filter and 'cat' the XML string to see if it gives you a result.

 

If you are running a script file, I would suggest trying to run it from the terminal and see if there are any errors or other output associated with the script aside from the XML

Link to comment

@smarg19: I've tried escaping but made no difference.

 

@deanishe: why?

 

@David: I've checked the output multiple times and I cannot spot any errors (that's the reason I've posted here). I'll take an example output and `cat` it. What if it doesn't work? What would be the next thing to look into?

Link to comment

WRT 1: Basically because generating valid XML can be tricky, but with an XML library, somebody else (who's smarter than you and me) has done the hard work for you. Using string templates to generate XML is a recipe for disaster, and it will almost certainly come back to bite you in the backside at some point.

 

WRT 2: Then you're going to have to post your actual workflow. You've posted valid XML and say your workflow throws no errors. There's not much more anyone can say without some code to poke a stick at.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...