🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #19235

XML caharcter attributes at beginning of a paragraph (VB)

#19235
From: Erwin Schwabe
Date: Mon, 13 Jan 2003 15:27
87 lines
4861 bytes
In this forum Some months ago there was a topic about creating XML character attributes. Olav Kvern posted a

script (see below) in which a routine is shown for XML character attributes in XML. Normaly I have not only one

paragraph in a story and if the first characters in a paragraph are formatted with a character style, control

codes are given back by the search function at the first 2 characters. The found item then could not be added as

XML tag. In the example code below, which can be inserted in the original code the error occures in the line

marked with: Paragraph error.



 
rem replace from here for the second example marked with '2 Paragraph 
myTextFrame.TextContents = "Adobe Magazine, Publish, MacUser, and ITC's U&lc are examples of magazines that have 

suspended publication in recent years." _ 
& vbCr & "Adobe Magazine2, Publish2, MacUser2, and ITC's 2U&lc2 are examples of magazines that have suspended 

publication in recent years." '2 Paragraph 
Rem Set the change preferences to change to our new character style 
myInDesign.ChangePreferences.CharacterStyle = myDocument.CharStyles.Item("XMLCharStyle") 
Rem Search for our example magazine titles and format them with the character style 
Set myFoundItem = myDocument.Search("Adobe Magazine", False, False, "") 
Set myFoundItsem = myDocument.Search("Publish", False, False, "") 
Set myFoundItem = myDocument.Search("MacUser", False, False, "") 
Set myFoundItem = myDocument.Search("U&lc", False, False, "") 
Set myFoundItem = myDocument.Search("Adobe Magazine2", False, False, "") '2 Paragraph 
Set myFoundItsem = myDocument.Search("Publish2", False, False, "") '2 Paragraph 
Set myFoundItem = myDocument.Search("MacUser2", False, False, "") '2 Paragraph 
Set myFoundItem = myDocument.Search("U&lc2", False, False, "") '2 Paragraph 
Rem Clear change preferences 
myInDesign.ChangePreferences = idNothing 
Rem Set up the XML infrastructure. 
Set myXMLStory = myDocument.XMLElements.Add(myXMLStoryTag, myTextFrame) 
Set myXMLBodyText = myXMLStory.XMLElements.Add(myXMLBodyTextTag, myTextFrame.Paragraphs.Item(1)) 
Set myXMLBodyText1 = myXMLStory.XMLElements.Add(myXMLBodyTextTag, myTextFrame.Paragraphs.Item(2)) '2 Paragraph 
Rem Find the words that have character style XMLCharStyle applied to them 
myInDesign.FindPreferences.CharacterStyle = myDocument.CharStyles.Item("XMLCharStyle") 
Set myFoundItems = myDocument.Search("") 
For mycounter = 1 To myFoundItems.Count 
    Set myFoundItem = myFoundItems.Item(mycounter) 
    Rem Add the XML element (this tags the text with the XML tag) 
    If mycounter < 5 Then '2 Paragraph 
    myXMLBodyText.XMLElements.Add myXMLTag, myFoundItem  
    Else '2 Paragraph 
    myXMLBodyText1.XMLElements.Add myXMLTag, myFoundItem '2 Paragraph error 
    End If 
Next 'myCounter





The code produces a second paragraph, sets the search and foramting and tries to set the character XML tags. I

tried the following:

 
myItem.Characters.Item(myIndex) = myItem.Parent.Characters.Item(myindex+1) 


but that didn't work. What the script should do: replace the original search result (char(Index_begin) to

char(Index_end)) to (char(Index_begin+1) to char(Index_end)) so that an object results without any control

codes. Can anybody help me?



 
Set myInDesign = CreateObject("InDesign.Application.2.0") 
Set myDocument = myInDesign.Documents.Add 
Rem Clear InDesign's find and change preferences 
myInDesign.FindPreferences = idNothing 
myInDesign.ChangePreferences = idNothing 
Rem Create a character style 
Set myCharacterStyle = myDocument.CharStyles.Add 
myCharacterStyle.Name = "XMLCharStyle" 
Rem Create a new XML tag 
Set myXMLStoryTag = myDocument.XMLTags.Add("story") 
Set myXMLBodyTextTag = myDocument.XMLTags.Add("body_text") 
Set myXMLTag = myDocument.XMLTags.Add("Magazine_Name") 
Rem Apply a fill color to the new style so that we can see it. 
myCharacterStyle.FillColor = myDocument.Colors.Item("Magenta")
Technical Details
Message-ID: <1de75a7e.-1@WebX.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-08!supernews.com!38.144.126.70.MISMATCH!feed3.newsreader.com!newsreader.com!news-xfer.cox.net!news.astraweb.com!news-small.astraweb.com!proxad.net!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!WebX

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,aa9b5e6b4780e106,start
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-01-13 07:39:10 PST
From: "Erwin Schwabe" <erwin.schwabe@wincor-nixdorf.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-01!sn-xit-08!supernews.com!38.144.126.70.MISMATCH!feed3.newsreader.com!newsreader.com!news-xfer.cox.net!news.astraweb.com!news-small.astraweb.com!proxad.net!fr.clara.net!heighliner.fr.clara.net!newsfeed01.sul.t-online.de!t-online.de!WebX
Newsgroups: adobe.scripting.indesign
Subject: XML caharcter attributes at beginning of a paragraph (VB)
Message-ID: <1de75a7e.-1@WebX.la2eafNXanI>
Date: Mon, 13 Jan 2003 07:27:25 -0800
Lines: 101
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit