-
1. Re: REVISED Puzzle: how to script adding XML parent?
SLTyPete Jan 4, 2013 11:21 AM (in response to SLTyPete)I'd love any hints, and/or confirmation that others can replicate this issue.
-
2. Re: REVISED Puzzle: how to script adding XML parent?
Loic_aigon Jan 4, 2013 3:01 PM (in response to SLTyPete)Hi,
Don't know if it helps but you can generate a parent XMLElement on the fly and move the xmlElement inside.
app.selection[0] is some tagged text.
"parentXE" is the markupTag you want to use for the parent
var refXE = app.selection[0].associatedXMLElements[0]; var parentXE = refXE.parent.xmlElements.add ( "parentXE" ); refXE.move ( LocationOptions.UNKNOWN , parentXE )
For the doc, consider Jongware html files.
And for any request regarding Adobe Products : https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform
It sems that CS7 is going to review the XML engine. It may be time to supply
Loic
-
3. Re: REVISED Puzzle: how to script adding XML parent?
SLTyPete Jan 4, 2013 6:57 PM (in response to Loic_aigon)Sorry Loic, that does NOT work.
Yes, you can generate an XML element on the fly and move things inside. But that's not the same as directly generating a PARENT element. There is a difference.
Here's a very very basic example that demonstrates the issue.
- Open the Structure view (ctrl-alt-1) and Paragraph Styles window.
- You'll see the two paragraphs each have their own XML tag and paragraph style; both are in a Story, which is in Root (as it should be).
- Double click in the Structure pane on either paragraph; you will see the Para Style for each is properly set.
- Open the Story editor (ctrl-Y). Everything will look "normal"
- Now select the first paragraph
- Step through the following minimal script (F10), while watching the structure pane
#target indesign var refXE = app. selection[0].associatedXMLElements[0]; var parentXE = refXE.parent.xmlElements.add ( "parentXE" ); refXE.move ( LocationOptions.UNKNOWN , parentXE );
The "parentXE" tag will first show up at the end of the Story. Then it will become the parent of Para1. (And will be at the end of the story).
If you now double click on the paragraphs and on parentXE, you will see some changes:
- parentXE has a paragraph style: PStyle2. That's because it was first placed at the end of the story, and absorbed the style of the neighboring PStyle2 paragraph.
- Para1 has now been given PStyle2 instead of PStyle1. That's because it is inside parentXE.
- ANYthing you move under parentXE will take on PStyle2 from now on!
You can replicate this in the UI:
- Close (without saving) and reopen the file.
- Select the Para1 (PStyle1) tag in the structure pane
- In the side menu, choose New Element and make a parentXE element
- The new element will be at the end, and (if you double click it) will have style PStyle2
- Drag the PStyle1 element underneath so parentXE is its parent. Now the PStyle1 element (double click to select) also has PStyle2
BUT if you slightly modify:
- Close (without saving) and reopen the file.
- Select the Para1 (PStyle1) tag in the structure pane
- In the side menu, choose New Parent Element and make a parentXE element
- The new element will already be the parent, and (if you double click it) will have NO paragraph style
- Drag any/all tags within... they all properly retain their formatting.
That's the issue in a nutshell.
Using "New Element" and making it parent (either in UI or in script) causes formatting to be broken/lost
But using "New Parent Element" in the UI works perfectly. I just don't know how to accomplish this in a script
Blessings,
Pete

