[Expat-discuss] extracting value other than element and attribute

yuki latt yuki.latt at gmail.com
Wed Aug 6 14:44:14 CEST 2008


Hello Nick,

    Thank you so much for your suggestion. I also realized that I am just
cheating. I knew that I have to implement the way you said. But I dont know
how I should handle XML_SetElementHandler and XML_SetCharacterDataHandler.
The former one helped me to find a tag.  But If I found a desired tag, I
dont know how to go to XML_SetCharacterDataHandler to extract the value.



Here is a piece of xml file I am working with.

<Company>
      many tags here
      <Building ID="1">
                 many tags here
                <area> length  width </area>
                 .....
      <Building ID="2">
                many tags here
                <area> length  width </area>
                 .....
</Company>

I'd to print as follows.

Building ID="1"
area = length  and width
Building ID="2"
area = length and  width


At first,  I used /expat/examples/elements.c file.  In that elements.c
file,  there is  XML_SetElementHandler(p, start, end);  in main().

Inside static void XMLCALL start(void *data, const char *el, const char
**attr),
 I made strcmp(el, "Building"). But I dont know how to go further to search
for <area> tag.

Without searching for <Building> tag,  I tried to find <area> tag only. If
found, I need to call a function to extract its value. But I cant make
function call to XML_SetCharacterDataHandler from XMLCALL start. ( I am
naive.)


Then I tried it as follows.

To extract element value,  I added
XML_SetCharacterDataHandler(p,elementText);  in main().

Inside void XMLCALL elementText(void *userData,const char *xmlData,int len),

 I searched for <area> tag inside it using strsr and  strcpy to get element
value after moving pointer a lot.



I am really sorry to bother you. If you dont mind, could you please teach
me?


regards,
yuki


More information about the Expat-discuss mailing list