Re: [xml] parent node property



Jagdev ,

 

Ur XML seems somewhat like………

 

<Crime> Crime_Value

     <Assault> Assault_Value </Assault>

     <Murder> Murder_Value </Murder >

     <computer_crime> computer_crime _Value </computer_crime >

     <theft>theft_Value </theft >

      .

      .

      .    

</Crime>

 

 

 

 

I guess u r using

 

(par_node->content)  or xmlNodeGetContent(par_node) which gives the combined string concatenated values of all children of par_node

 

(xmlNodeGetContent  API in Tree Module says ……….

Read the value of a node, this can be either the text carried directly by this node if it's a TEXT node or the aggregate string of the values carried by this node child's (TEXT and ENTITY_REF). Entity references are substituted

 

 

Remember always that TEXT content of a Xml Node is also a Child Node .

 

Use xmlNodeListGetString() API……….

 

So  to get only “Crime_Value” content  pass the 1st child of par_node to xmlNodeListGetString() API like this

 

xmlChar* pszCrimeContent  = xmlNodeListGetString(doc, par_node->children , 1)

 

 

Remember also to free the returned string using xmlFree() as it is allocated on heap via xmlNodeListGetString()

 

xmlChar* pszCrimeContent = NULL;

pszCrimeContent = xmlNodeListGetString(ptrXMLDoc , par_node->children , 1 );

if (pszCrimeContent)

{

            printf(“Value of <Crime>  = %s”, (const char*) pszCrimeContent);

            xmlFree(pszCrimeContent);

           pszCrimeContent = NULL;

}

 

 

 

 

Regds,

 

Lav

 


From: xml-bounces gnome org [mailto:xml-bounces gnome org] On Behalf Of Jagdev Bhogal
Sent: Friday, June 13, 2008 5:25 PM
To: xml gnome org
Subject: [xml] parent node property

 

 

Please see below.


From: Jagdev Bhogal
Sent: 13 June 2008 12:54
To: 'xml gnome org '
Subject:

 

Dear all

 

I am trying to build a parent-child array from an xml hierarchy.

So the array is {child value: parent value} eg {assault: crime}, {murder:crime}, {theft:crime} etc

I get the parent of a current node using par_node=cur_node->parent

 

but instead of giving me the name of the first element, its giving me all of the children as well.

 

What its giving me:

 

:0.000000: 0},{assault:

      crime

        murder

        computer_crime

        theft

        drug_trafficking

        sexual_assault

        assault

        torture

        kidnapping

        arson

        gang_activity

       

          criminal

          name

etc

 

What I would like:

{assault:crime}

 

Is there anyway I can just retrieve  the first name value ie crime?

 

Thank you for your help.

 

Mrs Jagdev Bhogal

Senior Lecturer in Database Systems

Dept. of Computing

Birmingham City University

Feeney Building

Perry Barr

Birmingham

B42 2SU

Tel: 0121 331 7658

 


Birmingham City University is the new name unveiled for the former University of Central England in Birmingham
For more information about the name change go to http://www.bcu.ac.uk/namechange/official_announcement.html

DISCLAIMER:
This email may contain confidential or privileged information for the intended recipient(s) and the views expressed in the same are not necessarily the views of Zensar Technologies Ltd. If you are not the intended recipient or have received this e-mail by error, its use is strictly prohibited, please delete the e-mail and notify the sender. Zensar Technologies Ltd. does not accept any liability for virus infected mails.



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