
I have a project which is nearing completion, but I've run into a problem. My ID document is a company directory. At the moment I am testing it with details for 50 companies, but the final output could be as many as 1,000. I've imported the data from a FileMaker database as XML. So far so good. Each 'Company' tag has an attribute containing the primary key of the company's details in the database. I would like to automatically find which page each company's details appear on, then write that page number as an another attribute in the 'Company' tag.
The reason I want to do this is so that I can export the updated XML back to FileMaker and update the table with the Page Number the company appears on. This step is quite important but I really don't want to edit attributes by hand! I'm sure this must be fairly easy for a Javascript guru, but I'm strictly a PHP/MySQL person and I'm a bit lost!
I would really appreciate it if someone could help me out with this!
Ian
Comments
Hi Ian,
I am not sure how you are wanting the XML updated with the page number of the item, if you could post a sample of the XML before and after the page is added I can look into how to create that?
Here is a short JS Sample showing how to get the page number from a page item in the document, obviously we would need to associate this with the relevent XML data but it should show the basic method.
startFunc();
function startFunc()
{
var myDoc = app.activeDocument
if ( myDoc)
{
var myPageItems = myDoc.allPageItems;
if ( myPageItems.length > 0)
{
for ( i =0; i< myPageItems.length; i++)
{
// I am just cycling through all the pageItems, obviously we would need to modify this to only pick up a specific companys information (but that depends on how the data is on the page)
myPageItem = myPageItems[i];
var returnNumber = findPageNumber ( myPageItem);
// THis is where you would we would then go on to add the data to the XML
}
}
}
}
// recursive function as we have to go from the PageItem we have till we get to the Page Object (which may be several items above where we start)
// I do not cover the problem if the item is not on a page.
function findPageNumber( pageItem)
{
var possibleParent = pageItem.parent;
var objectType = possibleParent.toString();
if ( objectType = "[Object Page]")
{
var props = possibleParent.properties;
return props.name;
}
else
{
return findPageNumber ( possibleParent);
}
}
Hope this provides some clarity.
Malcolm
Reply to this Comment
Malcolm:
Thanks for replying so promptly. This is the basic structure of my XML:
<Root>
<Company CompanyID="1" PageNo="">
<Name></Name>
<Address></Address>
<Numbers></Numbers>
<Email></Email>
<Web></Web>
<Activities></Activities>
</Company>
<Company CompanyID="2" PageNo="">
<Name></Name>
<Address></Address>
<Numbers></Numbers>
<Email></Email>
<Web></Web>
<Activities></Activities>
</Company>
...
</Root>
I'll flow it into one 4-col text frame per page. Once it's correctly marked up and fully paginated, I want to use JavaScript to loop through all the <Company> elements and find out which page each <Name> element is on, then update the PageNo attribute with the page number. Finally I'll export the XML and update my database with the Page Number data. Then I'll generate another, different, stream of XML which will use the Page Number data as a cross-reference to the original placed XML.
I hope I've made that clear!
regards
Ian
Reply to this Comment
Hi Ian,
Just wanted to check to see how you where getting on with this? Is there still anything that has you stumped?
Cheers
Malcolm
Reply to this Comment
Hi Malcom: Sorry it's taken so long to reply, but I'm heavily into a new project at the moment which is taking up a lot of my time. I'll prepare an example file of my progress to date and post it in the next few days.
All the best
Ian
Reply to this Comment