Re: [xml] Reading CDATA



On Fri, Sep 26, 2008 at 10:31:36AM +0200, Hartmut Sbosny wrote:
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.

  No API lack. You use an API to dump the content of a LIST of node
when you want the content of a SINGLE node.
  There is a zillion ways to get it like accessing directly the
node->content pointer  or using the API getting the content of 
a single node like xmlNodeGetContent()

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'?

  Hum, no I just tried to get you to understadn that the data model is
a tree and you need to walk that tree ... and xmllint --debug is a
convenient way to see this tree.

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/



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