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

Write XML from FrameMaker to a file with ExtendScript

Community Expert ,
Nov 23, 2020 Nov 23, 2020

Copy link to clipboard

Copied

It seems like I posted something like this a long time ago, but I am not sure. I have some table elements in an FrameMaker document that I want to write out to XML with ExtendScript. I find the XML object in ExtendScript very useful and I am hoping to use that instead of isolating each table and using Save As XML. I suppose I need some kind of recursive function to write the elements and attributes to XML, but if anyone has an algorithm already developed, I would appreciate seeing it (or just having it described in pseudocode). Thank you very much. -Rick

TOPICS
Scripting

Views

399

Translate

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
Community Beginner ,
Nov 23, 2020 Nov 23, 2020

Copy link to clipboard

Copied

Dear Rick,

Not sure if my answer is relevant to your query. But i had developed a script in vba.

I copy the table from Fm to word file.

Run the vba script, which simply wraps the respective elements around the content in each cell.

The logic i had used is.

1. The script selects the cell which is accomplished using select property.

2. Using the methods insertbefore and insertafter the respective elements are inserted around the selected cell.

3. This is done until the last cell in the table.

 

Votes

Translate

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
Enthusiast ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

Hi Rick,

I did something like that for the Adobe S1000D applicability handling system. I'm not at liberty to share the Adobe source code for that, but here's a general walk through of what I did:

  1. Create a recursive function that walks through the FrameMaker structure.
  2. For selected 'root' element create an ES XML object (it will need a temporary child element too or the XML Object isn't created.).
  3. Read the Attributes array for each FM attribute and create an equivalent ES Attribute object and append it to the current element.
  4. Check the current FM element for properties that are not present in the structure model such as graphic file references or xref format properties.
  5. Consider saving unstructured FM markers as XML processing instructions or XML elements if appropriate
  6. Walk the structure tree for each descendant FM element.
  7. You will now have an XML element object that is an exact match for the chosen FM structure.
  8. Create an ES File object and save the XML object to the file.

 

This method is really quick and to be honest feels more natural that FrameMaker's built-in XML handling as it does away with the need for read/write rules and EDD/template management.

Votes

Translate

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
Community Expert ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

Excellent Ian, thank you very much! I really like the ExtendScript XML object. I wish it was more feature rich, like with Xpath 3.1 support, but it is pretty good as is. I will try your approach. Fortunately, the table structure is pretty simple so it should be straight forward to script. Thanks again!

Votes

Translate

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
Enthusiast ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

Yes the XML object is very useful. I've been using it to pre-check XML documents where the doctype is the same for about 120 different schemas. I can query the content using the XPath 1.0 then select the required XML application for FrameMaker. It's so fast you wouldn't know it was happening!

In the past I've used XML as the format for configuration files using the ES XML object, but now I do that in JSON using the public domain JavaScript to JSON converter (json2.js). You only need to save the ES object as JSON then write it to a file. Reading is just as easy and converts the JSON back into an ES object. Couldn't be easier!

Votes

Translate

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
Community Expert ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

Are you using the json2.js converter right from ExtendScript? Can I go in either direction? I might want to store my tables as json files and then read them back in as XML.

Votes

Translate

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
Enthusiast ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

Yes Rick, the json2.js file can be included just as you would with an ExtendScript file. 

You convert an ExtendScript object to json using JSON.stringify(). To read from a json text file back into an ES object use JSON.parse().

 

I guessed that if you need an easy way to export reusable content JSON could be a more direct route than XML. Another useful feature to consider is that XSLT 3.0 can be used to read or write JSON too. So I have used JSON as configuration file that is initially written by ExtendScript and then used as a way to inject data into a FrameMaker pre or post XSLT transformation.

Votes

Translate

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
Community Expert ,
Nov 24, 2020 Nov 24, 2020

Copy link to clipboard

Copied

LATEST

Thanks for the generous help Ian. This might be useful for this project. I have a series tables that are modified after they are imported into FrameMaker (basically the sort order is updated to match a drawing). Each table is reused in multiple documents. Instead of using the default table on import, a script will use a lookup to see if the table has already been updated; if so, the updated table will be imported in its place. It may be more convenient to store the updated tables as JSON instead of XML. Thanks again.

Votes

Translate

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