CDATA problem

Discussion in 'XML' started by bestia9@hotmail.com, Dec 15, 2005.

  1. Guest

    Hello,

    I need a little help. I want to read the CDATA from an XML file :


    ....
    <EpgDescription>

    <![CDATA[ Matrix]]>

    </EpgDescription>
    ....

    I use this code to read the CDATA:

    Node EpgDescription =
    XPathAPI.selectSingleNode(ScheduleNodeListNode,"EpgDescription");

    Node firstchild = EpgDescription.getFirstChild();

    System.out.println("start
    :"+firstchild.getNodeName()+"-"+firstchild.getNodeValue()+" :end");

    The problem is when i Print my node name and my node value on the
    screen. I see this:

    start :#text-
    :end


    How can I print Matrix?

    Thx
    , Dec 15, 2005
    #1
    1. Advertising

  2. wrote:

    > <EpgDescription>
    >
    > <![CDATA[ Matrix]]>
    >
    > </EpgDescription>

    [...]
    > System.out.println("start
    > :"+firstchild.getNodeName()+"-"+firstchild.getNodeValue()+" :end");
    >
    > The problem is when i Print my node name and my node value on the
    > screen. I see this:
    >
    > start :#text-
    > :end


    The CDATA section is not the first child node of the EpgDescription
    element. It's text node with white space. Try looping over all child
    nodes and concatenate the values.

    --
    Johannes Koch
    In te domine speravi; non confundar in aeternum.
    (Te Deum, 4th cent.)
    Johannes Koch, Dec 15, 2005
    #2
    1. Advertising

  3. JAPISoft Guest

    Hello,

    Your code is correct but the problem is in your document structure, if
    you don't have a DTD or a Schema W3C, your blank text will be considered
    as text node too so your first child node is not the CDATA part but the
    previous blank part.

    Best wishes,

    A.Brillant
    EditiX - XML Editor and XSLT Debugger
    http://www.editix.com

    wrote:
    > Hello,
    >
    > I need a little help. I want to read the CDATA from an XML file :
    >
    >
    > ...
    > <EpgDescription>
    >
    > <![CDATA[ Matrix]]>
    >
    > </EpgDescription>
    > ...
    >
    > I use this code to read the CDATA:
    >
    > Node EpgDescription =
    > XPathAPI.selectSingleNode(ScheduleNodeListNode,"EpgDescription");
    >
    > Node firstchild = EpgDescription.getFirstChild();
    >
    > System.out.println("start
    > :"+firstchild.getNodeName()+"-"+firstchild.getNodeValue()+" :end");
    >
    > The problem is when i Print my node name and my node value on the
    > screen. I see this:
    >
    > start :#text-
    > :end
    >
    >
    > How can I print Matrix?
    >
    > Thx
    >
    JAPISoft, Dec 15, 2005
    #3
  4. Guest

    Thx guy's

    Problem is solved by loping all the childnodes i found the problem.
    there are 3 childnode's
    The first and last node are null.
    the second contains the Matrix

    THX

    Regards

    Marco
    , Dec 15, 2005
    #4
  5. wrote:

    > The first and last node are null.


    Well, not null, but whitespace.

    --
    Johannes Koch
    In te domine speravi; non confundar in aeternum.
    (Te Deum, 4th cent.)
    Johannes Koch, Dec 15, 2005
    #5
  6. Guest

    Indeed
    , Dec 15, 2005
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Forest
    Replies:
    0
    Views:
    312
    Forest
    Oct 20, 2003
  2. John Davison
    Replies:
    1
    Views:
    568
    Hal Rosser
    Jul 7, 2004
  3. Forest
    Replies:
    0
    Views:
    412
    Forest
    Oct 20, 2003
  4. Replies:
    3
    Views:
    736
    Joe Kesselman
    Mar 6, 2006
  5. Replies:
    2
    Views:
    756
    Peter Flynn
    Feb 29, 2008
Loading...

Share This Page