|Syntactic Confectionery Delight|
Accessing mixed content in XMLby anthski (Scribe)
|on Aug 09, 2005 at 22:42 UTC||Need Help??|
anthski has asked for the
wisdom of the Perl Monks concerning the following question:
I'm trying to use an XML based configuration file for a script and have hit a (common, I assume) problem where an element contains mixed content.
For example, a relevant snippet is:
The <img src="..."> tag here is a simplified example of an argument which may have more than one HTML style tag included as an attribute for the argument element.
The point is that I want to be able to tell my XML parser that anything contained within the <argument></argument> element should /always/ be treated as a single attribute, because sometimes it may contain HTML tags, and sometimes it may not.
I initially tried using XML::Simple to slurp the config file in as a hash but it doesn't support mixed content, so I've moved onto XML::DOM which boasts support for this, but for which I find the documentation somewhat confusing/unclear.
If I throw the following snippet of code at the aforementioned xml file
Then I end up with the error:
I assume that lots of people have at some stage wanted to include html tags inside an xml file, and not wanted their parser to try to offer it as a separate element with attributes. I might be wrong!
Any advice on what I can do would be appreciated.