Marking that a node contains HTML in XML
Howdy:
I have a number of data definitions that use the WYSIWYG type. One of our goals with this project is to publish XML to our webserver.
The problem that I'm running into is that downstream consumers
have no way of telling whether the content that was generated by a
WYSIWYG section is in fact HTML.
So here's an example:
.
.
.
<description>
<p>What's <strong>up</strong> with <em>that</em>?</p>
</description>
.
.
.
In order for downstream parsers to do the right thing with the
innards of the <description>
node, they need to
know that that node's contents should be treated like a text node,
not like an element node with children. So that means writing
potentially brittle code on the consumer side.
I've taken a look at the WYSIWYG's options and it doesn't look like there's a way to mark those nodes as containing HTML text.
It looks like adding an attribute via XSLT is fairly trivial
(<description content="html">
or
<description wysiwyg>
for example), and that
seems like a decent solution (although pushing the original problem
of brittleness back to the server isn't ideal, that's the place to
do it).
I was just wondering what others have done or if there's something I've overlooked or if HH has a best practice for this use case.
Thanks,
Greg
Discussions are closed to public comments.
If you need help with Cascade CMS please
start a new discussion.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
1 Posted by mdcarter on 13 Aug, 2015 04:36 PM
Greg-
I assume you are generally going to be just outputting the wysiwyg contents and not further parsing it as the structure may not be consistent. If you are looking to further parse the contents of the wysiwyg contents then I would wager that is probably not the best field type.
If you just want to output the contents of the wysiwyg field you can do the following:
<xsl:copy-of select="description/node()" />
Unless I am misunderstanding what you are trying to accomplish that should do it.
-Matt
2 Posted by Greg Gomez on 18 Aug, 2015 12:14 AM
Hey:
Good idea, but not quite what I need.
The problem is that parsers assume that the text in the WYSIWYG nodes is actually XML. So, if I want to convert it to JSON, for example, I get something like this (using the example XML from above):
Not really ideal.
Using a transform to wrap certain fields in CDATA tags in Cascade seems to be working, though. However, doing things that way also seems to violate XML standards. But it does work.
Thanks!
Greg
Ryan Griffith closed this discussion on 27 Aug, 2015 08:16 PM.