Extracting Text Strings from Text Nodes

Status
Not open for further replies.

Scott Crego

Usenet Archive
Joined
Jun 1, 2001
Messages
10
Reaction score
0
I have a problem with extracting text from a text node. I have set up the program as shown in many examples, wait for user to select an element with a text node, or in my case to select a cell.

I then step through the cell looking for all text and text nodes.

I then want to extract the text for putting in a Dialog box.

Here is the code that I am working with. The function I have tried is mdlText_extractStringsFromDscr.

I have looked all over the web and have found only a couple of references to this problem. Any help would be great.

Scott Crego

Private int extractdata /* <= returns info on what to do with element
*/
(
MSElementUnion *elementP, /* <=> element to be modified */ void *params, /* => user parameter */ int fileNum, /* => file # of current element */ MSElementDescr *elmDscrP, /* => element descriptor for element
*/
MSElementDescr **elmDscrPP /* <= if replacing entire descriptor
*/
)
MSElementDescr *tempEdP; /* traverses the element descriptor */ char string[256];

if (elementType == CELL_HEADER_ELM || elementType == SHARED_CELL_ELM) { tempEdP = elmDscrP->h.firstElem; strcpy(string, "");

while (tempEdP)
{
elementType = mdlElement_getType (&tempEdP->el);

if (elementType == TEXT_ELM)
{
mdlText_extractString (string, &tempEdP->el);
mdlText_expandString (string, string, sizeof (string), FRACTIONS | INTERNATIONAL);

fprintf(fp, "(%d) TEXT %s\n", counter, string);
}

if (elementType == TEXT_NODE_ELM)
{
holdEdP = tempEdP;
numnodes=tempEdP->el.text_node_2d.numstrngs;
//This is were it does do exactly what I want.
for (j=1; j<=numnodes; j++)
{
mdlText_extractStringsFromDscr (string, NULL, tempEdP); fprintf(fp, "TEXTNODE (%d of %d) (%s)\n", j, numnodes, string); tempEdP=tempEdP->h.next; counter++; } tempEdP=holdEdP; }

/* ----- point to the next element in the cell ----- */ tempEdP = tempEdP->h.next; } } return MODIFY_STATUS_NOCHANGE; }
 
Hi Scott,

You have some problems with the way you set up the function call mdlText_extractStringsFromDscr (string, NULL, tempEdP);

When you set the second argument to NULL only the total length of the text strings is returned. The "string" variable does not get filled. The argument should be set to the length of the "string" variable.

You don't need to use a loop. The function will return all the strings at once in one long buffer. If you have a text node with multiple strings then they will be separated in the buffer by newline characters.

Your variable "string" can only hold 255 characters. A large text node may overflow the variable.

Dan

On 5 Dec 2001 15:58:19 -0800, (Scott Crego) wrote:

I have a problem with extracting text from a text node. I have set up the program as shown in many examples, wait for user to select an element with a text node, or in my case to select a cell.

I then step through the cell looking for all text and text nodes.

I then want to extract the text for putting in a Dialog box.

Here is the code that I am working with. The function I have tried is mdlText_extractStringsFromDscr.

I have looked all over the web and have found only a couple of ...
 
Ok, thanks Dan, that solved the problem of getting the strings out of the text node. Now how do I know the total number of characters in the Text Node. Right now I made the "string" variable of size 500, but this now gets more than it should, it gets the rest of the text in the cell.

I have been trying to write a function to count the number of EOL (chr(10)) that occur and then truncate the string when the count of EOL's equals the number of strings in the Text Node.

Which I get from tempEdP->el.text_node_2d.numstrngs.

Scott
"Dan MacNeil" <dan.42@shaw{dot}ca> wrote:

Hi Scott,

You have some problems with the way you set up the function call mdlText_extractStringsFromDscr (string, NULL, tempEdP);

When you set the second argument to NULL only the total length of the text strings is returned. The "string" variable does not get filled. The
argument
should be set to the length of the "string" variable.

You don't need to use a loop. The function will return all the strings at
once
in one long buffer. If you have a text node with multiple strings then
they
will be separated in the buffer by newline characters.

Your variable "string" can only hold 255 characters. A large text node may overflow the variable.

Dan

On 5 Dec 2001 15:58:19 -0800, (Scott Crego) wrote:

>I have a problem with extracting text from a text node.
>I have set up the program as shown in many examples, wait for user to
>select an element with a text node, or in my case to select a cell.
...
 
Scott,

You can compare the total text node size to the size of "empty" text elements.

First get the size of the text node:
node_size = (tempEdP->el.text_node_2d.totwords + 19) * 2; // Size in bytes 19 is the number of words up the WID (totwords).

Now get the size of the "empty" text elements + the text node:
text node = 35 words
text element = 30 words (If we had no characters)

So:
empty_size = (35 + (30 * tempEdP->el.text_node_2d.numstrngs)) * 2; required_bytes = node_size - empty_size; // Add bytes for the newline characters the function inserts. required_bytes += tempEdP->el.text_node_2d.numstrngs;

If each of the text elements have an even number of elements the byte count will be exact. For instance, if you added numstrngs-1 for the newlines (which is all the newlines you will have) your buffer would be the same length as the text string. That of course is bad <g>.

If you have attribute data attached it increases the WID and will make the buffer larger.

I should also mention that I haven't actually tested any of this so you may have to tweak it a bit.

Hope this helps.
Dan
On Fri, 07 Dec 2001 00:53:18 GMT, "Scott Crego" wrote:

Ok, thanks Dan, that solved the problem of getting the strings out of the text node. Now how do I know the total number of characters in the Text Node. Right now I made the "string" variable of size 500, but this now gets more than it should, it gets the rest of the text in the cell.

I have been trying to write a function to count the number of EOL (chr(10)) that occur and then truncate the string when the count of EOL's equals the number of strings in the Text Node.

Which I get from tempEdP->el.text_node_2d.numstrngs.

...
 
Status
Not open for further replies.

Latest threads

Back
Top