0

We need to modify/update the xml attribute of .idms file. using actionscript. I'm using below approach to do that.

protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void
        {
            var file:File = File.desktopDirectory.resolvePath('myInputFile.xml');
            var fileStream:FileStream = new FileStream();
            fileStream.open(file, FileMode.READ);// doesn't read processing instrunction
            var xml:XML = new XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
            fileStream.close();
            var writeStream:FileStream =  new FileStream();
            writeStream.open(file, FileMode.WRITE);
            for each(var node:XML in xml.descendants("*"))
            {
                if(node.localName() == "Link")
                {   
                    var linkfile:String=node.@LinkResourceURI = "file:/Shared/Logos/Bk.ai";
                }
            }
            writeStream.writeUTFBytes(String(xml));
            writeStream.close();

        }

In above code problem is that it does not read processing instruction on top of xml file. in result after writing the xml file, it won't read the file as InDesign snippet file anymore. Processing instrunctions are:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

Can anyone help me in figure out how I can I read the processing instrunction as well in new file ?

Thanks for quick reply but Even though I've made this property as flase it's keep ignoring the processing instuction.

var file:File = File.desktopDirectory.resolvePath('031413115849909.idms');
            var fileStream:FileStream = new FileStream();
            XML.ignoreProcessingInstructions = false; //newly added
            fileStream.open(file, FileMode.READ);
            var xml:XML = new XML(fileStream.readUTFBytes(fileStream.bytesAvailable));
            fileStream.close();
mmmathur
  • 103
  • 12
  • When you say "ignoring the processing instruction," what exactly do you mean? How does this relate to InDesign? Are you saying that the XML output doesn't contain the processing instruction, and this is causing InDesign to fail to read the file? – Donald Smith Jul 29 '13 at 16:18

1 Answers1

0

There is a static property in the XML class called ignoreProcessingInstructions (which is true by default) that you could try setting before reading in your file. See this help page.

After some Google-ing, it appears that processing instructions outside of the root node may not be available, since the XML object starts with the root node. In that case, you may have to read the file in as standard text, save the processing line(s) before the root node, and then write them to the output file before you write the actual XML contents.

Donald Smith
  • 150
  • 1
  • 8
  • I've modified the code as per given insturction but it didn't help. I've updated my question with new lines. – mmmathur Jul 25 '13 at 03:21