6/01/2012

How to get the JournalStructure data

If you create a WebContent that is based on a structure / template combination and you want to get the value of one of the structure fields programmatically, you can do it like this:


Imagine, that your WebContent has the ID 21623 and you are looking for a field that has the name "Text1".


JournalArticle article = JournalArticleLocalServiceUtil.getArticle(21623);

Document document = SAXReaderUtil.read(article.getContentByLocale(Locale.ENGLISH.toString()));
Node node = document.selectSingleNode("/root/dynamic-element[@name='Text1']/dynamic-content");
String value = node.getText();

That´s all :) 

 If you like this post it would be very nice, if you could click on some of the google ads you see on the right side. It helps me run this block and motivates me ;)

If you have any questions, feel free to leave a comment.