capability of hiding XML tag

User 55ffa2f197

04-04-2012 23:46:44

Hi ,


I have a data field which is in XML format. When it shows up in the text wiget it has all those XML tags. I thought by changing the Mime-type to text/html or application/xml should hide those unwanted XML tags but it did not. Do you have plan to make this work or is there an alternative with current 5.9 client to do this. What I did is to use Customize Settings->Field Definition->Extra Attributes, then change mime-type to text/html.


It works for smiles field if I change the smiles field setting to text/structure, then the smilesĀ  will all show up as structures.


Thanks


Dong

ChemAxon fa971619eb

05-04-2012 08:08:03

XML cannot be handled in such a simple way. There would need to be some rules for how the XML should be processed and transformed to something that could be displayed (text, or HTML). The most general ways to do this could be:


1. allow an XSL stylesheet to be specified that defined the transform. This is not supported yet in IJC.


2. all the transform to be performed by a script (Groovy has very good support for XML). This could be done using a calculated field, but probably the only output format that could be supported currently is plain text.


Tim

User 55ffa2f197

05-04-2012 15:33:35










tdudgeon wrote:

2. all the transform to be performed by a script (Groovy has very good support for XML). This could be done using a calculated field, but probably the only output format that could be supported currently is plain text.



Hi Tim,


The 2nd option is very appealing. Let me lay out what I need to do in order to implement it, and tell me if I am off


1. in form design mode create a calculated text field which takes my original XML text field as variable


2. write groovy script to operate on the XML field and strip off the unwanted XML/HTM tags.


I am happy if the end result is plain text.


Thanks


Dong

ChemAxon fa971619eb

06-04-2012 12:25:12

Yes, that's exactly how you could do it. The groovy script would be part of a calcuated field.


You might want to look at Groovy's excellent XML handling tools, XmlParser and XmlSlurper.
http://groovy.codehaus.org/Processing+XML


These would make processing the XML pretty simple.


Tim

User 55ffa2f197

12-04-2012 01:05:09

Hi Tim,


My xml field in the database is not well formed a lot of them will chok the xmlslurp. Instead I choose to remove the tags. However I am getting an error saying following is bad script. Do not know why


return abstract.replaceAll(/<[^<]*>/,"")


even simple thing like return abstract.replaceAll("t","ggggg")


is treated as bad script


Dong

User 55ffa2f197

12-04-2012 01:31:51

OK, I noticed that in the script editor window the abstract is highlighted, that means it is groovy reserved key word (?) . With other field I intend to replace return fieldName.replaceAll(/<[^<]>/,"") works just fine. I guess I might need to change abstract field name to something else to avoid the clash


Dong

ChemAxon fa971619eb

16-04-2012 12:38:15

Hi Dong,


Yes, you will need to avoid using reserved words as variables. It shoudl be simple enough to come up with alternatives :-)


Tim