How to store a whole XML document as value in DB

Hi community,

In my Postgresql table, there is a column has the type of xml and I would like to persist the whole XML document there.

In Servoy app, I can read the content of XML document via a plugins plugins.XmlReader.readXmlDocumentFromFile. The returned value is an array of XmlNode.

At my first try, I simply assign the returned value to the column of the table via the foundset.

    var xmlsFS = datasources.db.mydatabase.my_table.getFoundSet();
    xmlsFS.newRecord();
    xmlsFS.xml_content = xmlNodes[0];
    databaseManager.saveData(xmlsFS);

It throws an error

ERROR com.servoy.j2db.util.Debug - Couldn’t convert: Node[name:catalog, type: ELEMENT] to media data

How can I overcome this issue?

Thanks

Hi,

your trying write an javascript object to the database into a media type column.

Basically 2 ways to overcome this:

  1. convert XML to a string and store it in a text column (create new column of type text with length ‘-1’)
  2. convert XML to a string, convert it to a byteArray: utils.stringToBytes(xmlString) and store it int the xml_content column you have right now.

Advantage of using option 1 is that the xml ends up as readable text in your database.

Hope this helps

mboegem:
Hi,

your trying write an javascript object to the database into a media type column.

Basically 2 ways to overcome this:

  1. convert XML to a string and store it in a text column (create new column of type text with length ‘-1’)
  2. convert XML to a string, convert it to a byteArray: utils.stringToBytes(xmlString) and store it int the xml_content column you have right now.

Advantage of using option 1 is that the xml ends up as readable text in your database.

Hope this helps

Hi Marc,

Cool! Thanks for your suggestion! 8)