Skip to main content
1-Visitor
May 23, 2017
Question

Can I use DOM parser to modify XML in Thingworx?

  • May 23, 2017
  • 3 replies
  • 5639 views

I tried using a DOM parser in Thingworx, but the result is DOM parser not defined, Is there any extension or any way I can use XML parser so that I can be able to perform the XML modifications without converting it every time for any modification.

3 replies

5-Regular Member
May 23, 2017

Hi Lipsa, I don't think there's any extension available on DOM, however have you checked the Universal Convertor though not sure if this is exactly what you are looking for as it converts the XML documents to Infotable

5-Regular Member
May 23, 2017

BTW for your DOM parser error I looked around not sure if you have already seen this but you'll need to define the  MIME type

var string = '<!DOCTYPE html><html><head></head><body>content</body></html>';

var doc = new DOMParser().parseFromString(string, 'text/html');

doc.body.innerHTML; // or doc.querySelector('body').innerHTML

See this for more detail

ldas11-VisitorAuthor
1-Visitor
May 23, 2017

Thanks, I tried this but DOM parser is not working in Thingworx

1-Visitor
May 23, 2017

Hello Lipsa Das​,

What did you tried already and with what result? If you need more advanced functions, you can always create a custom extension - in Java it is usually easier to handle more complex tasks.

Regards,

J.

ldas11-VisitorAuthor
1-Visitor
May 23, 2017

I tried using Universal converter, but it converts XML to infotable, then again from converting infotable to xml I am facing problem, If I could use DOM parser or any other XML parser then I could directly modify the changes that I have to do in XML file without converting it.

1-Visitor
May 23, 2017

Hi Lipsa Das​,

What kind of error you got? You try to do the conversion in the ThingWorx service? Please note, that in the services we can only use vanilla JavaScript.

Personally, I would create a ThingWorx extension and do any necessary parsing / conversion using the available Java libraries there. Do you need more information on how to create extension?

Regards,

J.

1-Visitor
May 23, 2017

One second, if you want to manipulate XML object from Server Side Javascript you have support Out Of the Box.

Server Side Javascript it's executed by Rhino JavaScript engine which implements ECMAScript for XML (E4X).

Best Regards,

Carles.

1-Visitor
May 24, 2017

Hi Carles,

No one denies this possibility, I just mentioned, that this is (relatively) easier, if you use Java with some useful libraries.

Regards,

J.