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 Please see below. From: Jagdev Bhogal 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 Perry Barr B42 2SU Tel: 0121 331 7658
DISCLAIMER: |