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

How to find out the page number of an xml element

Explorer ,
Oct 17, 2013 Oct 17, 2013

Hi everybody, sorry for my very bad english (french guy! logical). I hope you see what I'm looking for.

I'm scripting (javascript) an exporting script of every articles from a multi-pages indesign script.

In fact I could have one or more article in one file, every one of them is on an separate xml element. for each I have to export an xml file named with, first, the page number where appears the xml element, second, the number of exported article.

I'm success the second purpose, but not the first.

Someone have an idea ?

TOPICS
Scripting
3.6K
Translate
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

correct answers 1 Correct answer

Advocate , Oct 21, 2013 Oct 21, 2013

Hi kazegonzo,

Please try the below js code, I have access the doc/article/titre tag because the doc not placed into the pages,  you placed the titre tags so i access the titre tag and get the page number.

var myDoc=app.activeDocument;

var root = myDoc.xmlElements[0];

var docTag = root.evaluateXPathExpression('//doc//article//titre');

for(i=0; i<docTag.length; i++){

    var docPos = docTag.xmlContent.insertionPoints[0].parentTextFrames[0];

       alert("Page: "+docPos.parentPage.name);

       }

thx,

csm_p

...
Translate
Enthusiast ,
Oct 17, 2013 Oct 17, 2013

Hi,

I am not clear with your question, but if you want to find the page number of an xml element. The below link will help you:

http://forums.adobe.com/message/5308008#5308008

Vandy

Translate
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
Explorer ,
Oct 21, 2013 Oct 21, 2013

Hi vandy88, thanks and sorry for the late answer.

your answer is a great help for me, but it doesn't work. I get the following error message "undefined is not an object" about this line "alert(figCitationPage.name);"

Translate
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
Enthusiast ,
Oct 21, 2013 Oct 21, 2013

Which InDesign version you are using, if it is below cs5 the code wont work, then u need to work out in an alternate way

Vandy

Translate
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
Explorer ,
Oct 21, 2013 Oct 21, 2013

I'm using InDesign CS5.5

thx

Kazegonzo

Translate
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
Enthusiast ,
Oct 21, 2013 Oct 21, 2013

Try this,

var myDoc=app.activeDocument;

var root = myDoc.xmlElements[0];

var docTag = root.evaluateXPathExpression('//doc');

for(i=0; i<docTag.length; i++)

{

    var docPos = docTag.insertionPoints.lastItem();

    var docFrame = docPos.parentTextFrames[0];

    var docPage;

    try

    {

         docPage = docFrame.parentPage;

     }

catch(e)

    {

        docPage = docFrame.parent.name;

     }

    alert(docPage.name);

}

Vandy

Translate
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
Explorer ,
Oct 21, 2013 Oct 21, 2013

i try your new solution. i get the following error message.

error message.png

I don't understand why ?

Translate
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
Advocate ,
Oct 21, 2013 Oct 21, 2013

Hi kazegonzo,

Please try the below js code, I have access the doc/article/titre tag because the doc not placed into the pages,  you placed the titre tags so i access the titre tag and get the page number.

var myDoc=app.activeDocument;

var root = myDoc.xmlElements[0];

var docTag = root.evaluateXPathExpression('//doc//article//titre');

for(i=0; i<docTag.length; i++){

    var docPos = docTag.xmlContent.insertionPoints[0].parentTextFrames[0];

       alert("Page: "+docPos.parentPage.name);

       }

thx,

csm_phil

Message was edited by: csm_phil

Translate
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
Explorer ,
Oct 21, 2013 Oct 21, 2013
LATEST

hi csm_phil,

I understood my mistake. Thanks you and Vandy too. you are very helpful and patient to me.

I have just to put the return in a variable and it's done.

thx

kazegonzo

Translate
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
Advocate ,
Oct 21, 2013 Oct 21, 2013

Hi kazegonzo,

Better you give some snapshots, your InDesign document xml structure and which tags you need to access and get the page number format.

thx,

csm_phil.

Translate
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
Explorer ,
Oct 21, 2013 Oct 21, 2013

Hi csm_phil, pleased to see you.

what I trying to get is the page number for each tag "doc".

xml Structure.png

thanks for your help.

Kazegonzo

Translate
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