Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

FDK : element order, prop, ID?

New Here ,
Sep 08, 2008 Sep 08, 2008

Copy link to clipboard

Copied

Hello,

I need to develop an automate to get prop of an element before an action and to set it after the action.

Before an action, it will search all P elements of the document that are before B elements. P is Paragraph (pgf).

Rbody

--B
--P (this one will not be good)


Rbody

--P (this one will be good)
--B

So, i want to get all the ID and prop of P elements that are before B elements.

I have tried a lot of things like go from P to P and on each P find the next sibling element and check if it's B element :

//fdk guide code + custom
F_ObjHandleT docId, pgfId, nsibId;
StringT b;
b=F_StrCopyString((StringT)"B");
docId = F_ApiGetId(0, FV_SessionId, FP_ActiveDoc);
pgfId = F_ApiGetId(FV_SessionId, docId, FP_FirstPgfInDoc);
while (pgfId)
{
nsibId = F_ApiGetId(docId, pgfId, FP_NextSiblingElement)
if(F_StrCmpN(F_ApiGetString(docId, nsibId , FP_Name), b, F_StrLen(b)==0)
{
F_Printf(NULL, "I'M VERY HAPPY\n");
}
pgfId = F_ApiGetId(docId, pgfId, FP_NextPgfInDoc);
}

it doesn't work, nsibId is 0.

it seems that i need to make a selection of the text but i'm not sure...

I don't well understand the logic to navigate through a document.

Do you know how to make this?

Thank you,
Alexandre
TOPICS
Structured

Views

700
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Sep 08, 2008 Sep 08, 2008

Copy link to clipboard

Copied

Hi Alexandre,

You are going about this the wrong way. If you are attempting to navigate a structure tree, you need to start with element IDs, not paragraph IDs. Basically, you should:

1 - Get the ID of the flow that contains the structure tree, maybe something like:

flowId = F_ApiGetId(FV_SessionId, docId, FP_MainFlowInDoc);

2 - Get the ID of the highest-level element in the flow, something like:

elemId = F_ApiGetId(docId, flowId, FP_HighestLevelElement);

... then you can use the FP_FirstChildElement, FP_NextSiblingElement, etc. properties of the elemId to walk through the tree. You can't call FP_NextSiblingElement on a paragraph ID because this is an element property only... paragraphs have no concept of parents, children, and siblings.

Also, to get the name of an element, you need to get the name of its underlying element definition. Something like:

F_ObjHandleT elemDef;
StringT elemName;

elemDef = F_ApiGetId(docId, elemId, FP_ElementDef);
elemName = F_ApiGetString(docId, elemDef, FP_Name);

...in other words, you can't get the tag name directly from the element. The name is a property of the element definition in the imported EDD.

Russ

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 08, 2008 Sep 08, 2008

Copy link to clipboard

Copied

Thank you for your answer,

I have :

-Section
-P
-B
-Rd
-B
-K
-P

If i want the B next to the first P, i will have to use FP_NextSiblingElement until i have F_StrCmpN((StringT)"B", elemName, F_StrLen(elemName))==0?

In other words, the order of element is respected with FP_NextSiblingElement or i can have the second B instead of the one?

Thank you,
Alexandre

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Sep 08, 2008 Sep 08, 2008

Copy link to clipboard

Copied

Alexandre,

I don't quite understand everything you are asking. I think you have the general idea, though. Let's say that you have:

elemId = {the P element}

...if this is the case, then say:

name1 = F_ApiGetString(docId, F_ApiGetId(docId, elemId, FP_ElementDef), F_Name);

and then, say:

elemId2 = F_ApiGetId(docId, elemId, FP_NextSiblingElement);
name2 = F_ApiGetString(docId, F_ApiGetId(docId, elemId2, FP_ElementDef), FP_Name);

...in this case, then:

F_StrCmp(name1, name2) == 0

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Sep 08, 2008 Sep 08, 2008

Copy link to clipboard

Copied

Thanks for your reply,

I don't understand something in your code :

you say : name1={P name} and name2 = {{nextSiblingElement P element} name}
if {nextSiblingElement P} != {P element} then F_StrCmp(name1, name2)!=0
if {nextSiblingElement P} == {P element} then F_StrCmp(name1, name2)==0

may be I am in error, sorry for the misunderstood.

My question was, i have :
-P
-B
-K

{nextSiblingElement P element} = B or K?

The order of the element is important for the tool that i develop.

Thanks,
Alexandre

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Sep 08, 2008 Sep 08, 2008

Copy link to clipboard

Copied

LATEST
Right, sorry. What I should have said was:

...then

F_StrCmp(name1, "P") == 0
F_StrCmp(name2, "B") == 0

The next sibling to P is B.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines