Re: [xml] Reading CDATA



Hi Daniel,

On Thursday, 25. September 2008 17:05, Daniel Veillard wrote:
On Wed, Sep 17, 2008 at 06:48:37PM +0200, Hartmut Sbosny wrote:
Hello,
I am fresh to libxml. I want to read an xml file containing
the part
    <data>
            <![CDATA[...]]>
    </data>

Currently I use the xmlParseDoc() interface. My first try was to read the
<data> node string via xmlNodeListGetString(). This returns something

  You just can't using that API.

Is this a principle limitation of the xmlParseDoc API or only an 
accidental API lack? Which API is suitable to read cdata? Sorry for my
stumbling asking, I am new to libxml and xml.



From there I could in princple extract the pure "..." content by
subtracting the trailing white space node string, but it seems to me
there should exist an easier libxml way to read the CDATA content?

wei:~/XML -> cat tst.xml
<data>
   <![CDATA[...]]>
</data>

wei:~/XML -> xmllint --debug tst.xml
DOCUMENT
version=1.0
URL=tst.xml
standalone=true
  ELEMENT data
    TEXT compact
      content=
    CDATA_SECTION
      content=...
    TEXT compact
      content=
wei:~/XML ->

 navigate in the tree and grab the data as content-> from the second
child of your containing element

I probably miss the point. Do you mean I should use the command line 
tool 'xmllint'? This would be rather inconvinient for me. I have ready (more 
or less) a C program - using the xmlParseDoc API - which reads an XML file, 
where the cdata content is only a small piece of. As a workaround to get 
the cdata I evaluate currently the three strings
        "___...___"
        "...___"
        "___"
(in the said symbolic meaning) which I get when I parse through the 
children of the <data> element using xmlNodeListGetString(). Is that 
something I should not rely on?

Thanks for your response
Hartmut



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]