I am trying to update a webcontent article in java. However I only want to update a specific field, I tried to use the updateContent method from JournalArticleServiceUtil. And this works but I can't figure out how to only update ONE field.
What I tried to do, was altering the content xml so i would only fill in one field.
String content = "<?xml version=\"1.0\"?><root available-locales=\"nl_NL\" default-locale=\"nl_NL\"><dynamic-element name=\"foto\" type=\"text\" index-type=\"keyword\" instance-id=\"xedagpof\"><dynamic-content language-id=\"nl_NL\"><![CDATA[" + fotoUUID + "]]></dynamic-content></dynamic-element></root>";
But this doesn't work. It merely edits this field and clears out the others. So I'm stuck thinking there are two ways of fixing it. Either getting the values of the webcontent I am editting or somehow editting only one value.
Does anyone have an idea how I could resolve this issue?
So I've been able to do this myself, what I've done get the content of the webcontent I am trying to edit and save it in a document type variable. Then I've retrieved the individual fields using SAXReaderUtil.getValueOf. I saved them as variables and inserted them into the new xml content.
Document document = SAXReaderUtil.read(journal.getContent());
String beschrijving = document.valueOf("/root/dynamic-element[@name='beschrijving']/dynamic-content/text()");
String latitude = document.valueOf("/root/dynamic-element[@name='latitude']/dynamic-content/text()");
String longitude = document.valueOf("/root/dynamic-element[@name='longitude']/dynamic-content/text()");
String content = "<?xml version=\"1.0\"?><root available-locales=\"nl_NL\" default-locale=\"nl_NL\"><dynamic-element name=\"beschrijving\" type=\"text_box\" index-type=\"text\" instance-id=\"jtremtjm\"><dynamic-content language-id=\"nl_NL\"><![CDATA[" + beschrijving + "]]></dynamic-content></dynamic-element><dynamic-element name=\"latitude\" type=\"text\" index-type=\"keyword\" instance-id=\"xcoidjfq\"><dynamic-content language-id=\"nl_NL\"><![CDATA[" + latitude + "]]></dynamic-content></dynamic-element><dynamic-element name=\"longitude\" type=\"text\" index-type=\"keyword\" instance-id=\"ydugvlqc\"><dynamic-content language-id=\"nl_NL\"><![CDATA[" + longitude + "]]></dynamic-content></dynamic-element><dynamic-element name=\"foto\" type=\"text\" index-type=\"keyword\" instance-id=\"xedagpof\"><dynamic-content language-id=\"nl_NL\"><![CDATA[" + fotoUUID + "]]></dynamic-content></dynamic-element></root>";
I hope if someone is looking to do the same this helps!