[JS] Write an xml file.


Hello.


I want to write xml file using JavaScript only. (Without the xml in the document tag.)


I tried to code below, but error.


Please any advice for me.


Thank you.

main()
function main()
{
    var myDocument = app.activeDocument;
    var myDocumentSize = myDocument.documentPreferences.pageSize;
    var myDocumentWidth = myDocument.documentPreferences.pageWidth;
    var myDocumentHeight = myDocument.documentPreferences.pageHeight;
    
    var tfCount = myDocument.textFrames.count();

    var tfContentsArr = new Array(tfCount);
    var tfGeometricArr= new Array(tfCount);

    for(var i=0; i<tfCount; i++)
    {
        tfContentsArr[i] = myDocument.textFrames.item(i).contents;
        tfGeometricArr[i] = myDocument.textFrames.item(i).geometricBounds;
    }
    var tagRoot = new XML("<Info>");
    tagRoot[0].DocInfo[0].DocSize[0] = myDocumentSize;
    tagRoot[0].DocInfo[0].DocWidth[0] = myDocumentWidth;
    tagRoot[0].DocInfo[0].DocHeight[0] = myDocumentHeight;

    for(var i=0; i<tfCount; i++)
    {
        tagRoot[0].ItemInfo[0].Story[i].contents[0] = tfContentsArr[i];    // error point.   If the <Story>tag two or more.
        tagRoot[0].ItemInfo[0].Story[i].GeometricBounds[0] = tfGeometricArr[i];
    }

    alert(tagRoot.toXMLString());

    var settingsFile = File(Folder.desktop + "/CompleteDocumentXML.xml");
    settingsFile.open ("w");  
    settingsFile.write ("<?xml version='1.0'?>\r" + tagRoot);
    settingsFile.close ();  
}






The output I want:

< info >

< DocInfo >

Size of < DocSize > < / DocSize >

Width of < DocWidth > < / DocWidth >

Height of < DocHeight > < / DocHeight >

< / DocInfo >

< ItemInfo >

< Story >

< content > content < / summary >

< GeometricBounds > GeometricBounds < / GeometricBounds >

< / history >

< Story >

< content > content < / summary >

< GeometricBounds > GeometricBounds < / GeometricBounds >

< / history >

.....

< / ItemInfo >

< / info >

No, sorry, I see now how to enter the code in this forum.

In line 26, you try to write about history [i] .silence before story [i] even exist.

If you create story [i] first of all, you should have no problem.

that is, precede the line 26 with:

tagRoot [0]. ItemInfo [0]. History [i] = ' to the ';

Tags: InDesign

Similar Questions

  • Write an xml file - how to value the question

    I'm writing an XML as follows:
    <? XML version = "1.0" encoding = "utf-8"? >... < attribute tag = VR "00080008" = "CS" > ORIGINAL\PRIMARY\WHOLE BODY\EMISSION < / attribute > < tag attribute "00080012" VR = "DA" = > 20100302 < / attribute >...
    I have no problem affecting the Tag = "00080008" and VR = "CS". What makes me mad is how to define the string ORIGINAL\PRIMARY...

    What I get is:
    < attribute tag = VR "00080018" = "User Interface" / > with no inserted string. (Ignore the fact that the tags are different, will make any tag). I would like the string, then the closing < / attribute >. Mine closes immediately.
    The code is:
    Attrib element;
    ....
    attrib = doc.createElement ("Attribute");
    tmp = makeHex4(grpEl[0]) + makeHex4(grpEl[1]);
    attrib.setAttribute ("Tag", tmp);
    attrib.setAttribute ("RV", varType);
    attrib.setNodeValue (metaVal);
    instance.appendChild (attrib);

    I thought that the attrib.setNodeValue (metaVal) would do the trick, but it doesn't. I have also thought about using attrib.appendChild (metaVal), but that does not make sense since I should add a node, not a string.

    Since I was the example file, I know that we can somehow, but I don't know how to do it. I would appreciate a suggestion from someone who knows more about the topic I am doing.

    Thank you
    Ilan

    Monitor all that supports the dom will return with this, assuming metaVal is the content string (with the backslash escaped well, say, if applicable).

    attrib.appendChild(doc.createTextNode(metaVal));
    

    If she supports (at least partially) dom level 3, it probably supports this as well.

    attrib.setTextContent(metaVal);
    
  • Reading an XML file and write the content in another file xml in java

    Hello

    I'm new to xml parsing. My requirement is that I get a message (xml) using ibm MQ in the ByteArrayInputStream format. I read this xml message and write to another file.

    To do this, I create a CEP.

    First of all, I used simple reading and writing concept, but the output is "java.io.FileInputStream@3e25a5".
    Example of xml file
    -< customer >
    < > 1234 ClientId < / ClientId >
    STechnology < ClientName > < / ClientName >
    < DTU_ID > 567 < / DTU_ID >
    < ClientStatus > ACTIVE < / ClientStatus >
    -< LEAccount >
    < Customer > 678989 < / customer >
    < > 56743 LEId < / LEId >
    -< account >
    < AccountNumber > 9876543678 < / account number >
    < / account >
    < / LEAccount >
    -< Service >
    Y2Y < Cindicator > < / Cindicator >
    < PrefCode > 980 < / PrefCode >
    < BSCode > 876 < / BSCode >
    < MandatoryContent > MSP < / MandatoryContent >
    < / service >
    < / customer >

    Code:


    import java.io.ByteArrayInputStream;
    import java.io.FileInputStream;
    to import java.io.FileOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.OutputStream;

    public class ByteArrayInputStreamToXml {}

    Public Shared Sub main (String [] GIS) throws IOException {}

    InputStream inputStream = new FileInputStream("C:\\soft\\test2\\sample1.xml");
    currentXMLBytes Byte = inputStream.toString () .getBytes ();
    ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream (currentXMLBytes);

    OutputStream out = new FileOutputStream("C:\\soft\\test\\data.xml");
    int read = 0;
    ubyte bytes [] = new byte [1024];

    While ((read = byteArrayInputStream.read (bytes))! = - 1) {}
    out. Write (bytes, 0, read);
    out. Write ("\n");
    }

    inputStream.close ();
    out. Flush();
    out. Close();

    System.out.println ("new file created!");

    }

    }

    Please suggest me how can I use DOM/SAX parser, I see several code on the net to read the xml file using SAX/DOM parser, but write an xml file after reading using ByteArrayInputStream I don't get. Assistance through some link examples will also be useful for me.

    Thank you
    Sumit

    Published by: user8687839 on April 30, 2012 02:37

    Published by: user8687839 on April 30, 2012 02:43

    user8687839 wrote:
    But the file is coming thanks to a queue and byte format. Must read the byte, and write to a file. So, how I tried to read the byte using the code above. Please suggest me the correct way.

    Simply write the bytes of the contents of the queue directly to a FileOutputStream. Still no need to SAX or DOM!

    Pseudo-code-

    Open a FileOutputStream .
    
    Until all the bytes of the queue have been read
        read some bytes from the queue.
        wite these bytes to the FileOutputStream.
    
    Close the FileOutputStream.
    

    Published by: sabre150 on April 30, 2012 11:30

  • Write several bays in one xml file at different times without overwriting the old file?

    Hi my name is Dustin,

    I am new to labview and teststand... I try several tables of data in a single XML right. I can do this with a cluster but I need to create a variable for each of these pictures (21 pictures) and I was hoping to use the same variable for each table. Which means that I get my data table write in an xml file and replace this table in this variable with a new table and then call my VI who writes this table in an xml file and write to the same file xml under the first table without crushing. My VI I created to write a table to an xml file is attached. Yet once I wonder if there is a way to write several berries in a single at different times xml file, without overwriting the old file xml.

    Thank you

    Hi dlovell,

    See the attached example. I think he can help you.

    Kind regards
    Nitz

    (Bravo to give good answers, mark it as a Solution If your problem is resolved)

  • Read and write to the local XML file

    Hello

    I'm trying to understand how to use the xml files saved locally. My goal is to create an xml file in the repository of the application (which has read/write permissions), add data in this file xml and re - register so that it can be retrieved whenever this is necessary.

    I want to store xml data are farily short; It has the following structure:

    
        x
        x
        x
        x
        x
        x
        x
        x
        x
        x
    
    
    
    ...etc.
    

    I read a few articles about recording and writing in a file like this, but none of them does not seem to work. I hope someone could provide me with the code to do this.

    Thank you.

    Try:

    ///////////////////////////////////////////////////////////////////////

    public public static function Store (name: String, data: String): void

    {

    var file: file = File.applicationStorageDirectory.resolvePath (name);

    var file_stream: FileStream = newFileStream();

    file_stream. Open (file, FileMode.WRITE);

    out of the var : String = '\n';

    output of +=;

    output = output.replace (\n/g, File.lineEnding);

    file_stream.writeUTFBytes (output);

    file_stream. Close();

    }

    //////////////////////////////////////////////////////////////////////////

    public public static function Get (name: String): XML

    {

    var config: XML = null;

    var file: file = File.applicationStorageDirectory.resolvePath (name);

      if (file.exists)

    {

    var file_stream: FileStream = new FileStream();

    file_stream. Open (file, FileMode.READ);

    config = new XML (file_stream.readUTFBytes (file_stream.bytesAvailable));

    file_stream. Close();

    }

    return config;

    }

  • problem write/read an xml file

    Hello world

    IM using ksoap library to access my webservice, if everything is ok, my webservice returns an xml file, then I use this file to show some information in my application.

    In the Simulator, everything works perfectly (BB simulator_5.0.0.411_8900), but in a real BB does not work, the app show me a NullPointerException.

    Anyone has an idea about this?

    public void CargaDatosIniciales(){
    
        String result="";
    
        String serviceUrl = "http://myserver.com/blackberry/soap.php";
        String serviceNamespace ="http://myserver.com/blackberry/soap.php";
        String soapAction = "http://myserver.com/blackberry/soap.php?wsdl";
    
        rpc = new SoapObject(serviceNamespace,"cargarVideos");
        rpc.addProperty("Login", usr);
        rpc.addProperty("Password", password);
        rpc.addProperty("user_agent", userAgent);
    
        try{
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.bodyOut = rpc;
            envelope.dotNet = false;
            envelope.encodingStyle = SoapSerializationEnvelope.XSD;
    
            HttpTransport ht = new HttpTransport(serviceUrl);
            ht.debug = true;
            ht.call(soapAction, envelope);
            result = (envelope.getResult()).toString();
            writeXML(result,1);
    
        }catch(Exception e){
    
        }
    
    }
    
    private void writeXML(String result,int f) {
    
        String URL = "file:///SDCard/BlackBerry/documents/";
        String filename="";
        if(f==1){
    
            filename = "datosXML.xml";
        }
    
    ....
        String fName=URL+filename;
        try {
             DataOutputStream os = null;
                FileConnection fconn = null;
                try {
                        fconn = (FileConnection) Connector.open(fName, Connector.READ_WRITE);
                        if (!fconn.exists()){
                            fconn.create();
                        }
                            fconn.delete();
                            fconn.create();
    
                        os = fconn.openDataOutputStream();
                        os.write(result.getBytes());
                } catch (IOException e) {
                        System.out.println(e.getMessage());
                } finally {
                        try {
    
                            if (null != os)
                                        os.close();
                                if (null != fconn)
                                        fconn.close();
                        } catch (IOException e) {
                                System.out.println(e.getMessage());
                        }
                }
    
        } catch ( Exception e ) {
    
        }      
    
    }
    

    PD: Sorry for my English.

    In most cases, 'deviceside = true' does not work unless it is accompanied by specific carrier APN info.

    The AFN must be defined in the parameters of TCP devcie or added to your URL.

    See the following article:

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/What_Is...

    .. and this one:

    http://www.BlackBerry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800451/800563/How_To _...

  • How to write the xml data to a file in pl/sql

    Hello

    DB version: 11.2.0.2.0

    Apps Version: 12.1.3

    We try to generate an xml file in a directory on the server through pl/sql program. Here is the code we use. But it gives an error like ' failed due to the ORA-01422: exact fetch returns more than number of lines. When we put the select statement in a cursor and try to write data one by one in the loop, it is written only one record. Please tell us if we make a mistake.

    -The code in error

    CREATE or REPLACE PROCEDURE TEST_XML_CREATE (errbuf OUT VARCHAR2

    ERRCODE OUT NUMBER)

    IS

    l_file_name VARCHAR2 (30);

    l_file_path VARCHAR2 (200);

    l_xmldoc CLOB.

    BEGIN

    l_file_path: = 'FTPPOST_OUT_GTI_AUDIT ';

    l_file_name: = 'TEST_XREF4.xml ';

    SELECT

    XMLElement ("financialorganization:LegalEntityList",

    xmlattributes ('http://schema.bppost1.be/entities/financial/financialorganization/v001' "xmlns:financialorganization", )

                       ' http://schema.bppost1.be/entities/base/BaseTypes/V001 ' 'xmlns:basetype',

                       ' http://www.w3.org/2001/XMLSchema-instance ' "xmlns: xsi"),

    XmlElement ("financialorganization:LegalEntity",

    XmlElement ("financialorganization:LegalEntityCode", fv.flex_value)

    XmlElement ("financialorganization:Description", fv.description)

    XmlElement ("basetype:ValidityPeriod",

    XmlElement ("basetype:OpenEndedPeriod",

    XmlElement ("basetype:StartDate", TO_CHAR(start_date_active,'YYYY-MM-DD')),

    XmlElement ("basetype:EndDate", TO_CHAR (end_date_active, 'YYYY-MM-DD'))

    )

    )

    )

    ). getClobVal()

    IN l_xmldoc

    Of

    fnd_flex_value_sets fvs,

    fnd_flex_values_vl fv

    WHERE 1 = 1

    -to be replaced by the name parameter value

    AND fvs.flex_value_set_name = 'iPROMIS_POST_GL_AFK01_ENTITEIT. '

    AND fvs.flex_value_set_id = fv.flex_value_set_id

    AND fv.summary_flag = 'n';

    dbms_xslprocessor.clob2file (l_xmldoc, l_file_path, l_file_name, nls_charset_id ('UTF8'));

    END;

    /

    The XML format we want to generate is less than

    ============================================

    < financialorganization:LegalEntityList

    ' xmlns:financialorganization = ' http://schema.bppost1.be/entities/financial/financialorganization/V001 "

    ' xmlns:basetype = ' http://schema.bppost1.be/entities/base/BaseTypes/V001 "

    " xmlns: xsi =" http://www.w3.org/2001/XMLSchema-instance ">

    < financialorganization:LegalEntity >

    < financialorganization:LegalEntityCode > 12345 < / financialorganization:LegalEntityCode >

    < financialorganization:Description > Test Description < / financialorganization:Description >

    < basetype:ValidityPeriod >

    < basetype:OpenEndedPeriod >

    < basetype:StartDate > 1900 - 01 - 01 < / basetype:StartDate >

    < / basetype:OpenEndedPeriod >

    < / basetype:ValidityPeriod >

    < / financialorganization:LegalEntity >

    < financialorganization:LegalEntity >

    < financialorganization:LegalEntityCode > 54321 < / financialorganization:LegalEntityCode >

    Test Description1 < financialorganization:Description > < / financialorganization:Description >

    < basetype:ValidityPeriod >

    < basetype:OpenEndedPeriod >

    < basetype:StartDate > 1900 - 01 - 01 < / basetype:StartDate >

    < / basetype:OpenEndedPeriod >

    < / basetype:ValidityPeriod >

    < / financialorganization:LegalEntity >

    < / financialorganization:LegalEntityList >

    Kind regards

    Pirre

    You must use the XMLAGG function to group LegalEntity items in a single fragment.

    Also use XMLSERIALIZE instead of the getClobVal method (it is not recommended).

    SELECT XMLSerialize(document
              XMLElement("financialorganization:LegalEntityList",
                xmlattributes('http://schema.bppost1.be/entities/financial/financialorganization/v001' "xmlns:financialorganization",
                             'http://schema.bppost1.be/entities/base/basetypes/v001' "xmlns:basetype",
                             'http://www.w3.org/2001/XMLSchema-instance' "xmlns:xsi"),
                XMLAgg(
                  xmlelement("financialorganization:LegalEntity",
                        xmlelement("financialorganization:LegalEntityCode", fv.flex_value),
                        xmlelement("financialorganization:Description", fv.description),
                        xmlelement("basetype:ValidityPeriod",
                            xmlelement("basetype:OpenEndedPeriod",
                                xmlelement("basetype:StartDate", TO_CHAR(start_date_active,'YYYY-MM-DD')),
                                xmlelement("basetype:EndDate", TO_CHAR(end_date_active, 'YYYY-MM-DD'))
                            )
                        )
                  )
                )
              )
           )
      INTO l_xmldoc
      FROM
        fnd_flex_value_sets fvs,
        fnd_flex_values_vl fv
    WHERE 1 = 1
        -- to be replaced by value set name parameter
       AND fvs.flex_value_set_name = 'iPROMIS_POST_GL_AFK01_ENTITEIT'
       and fvs.flex_value_set_id = fv.flex_value_set_id
       and fv.summary_flag = 'N';
    
  • Write in an external xml file

    OK, so ive been reading on xml and found theres this big thing appeal. appendChild(). that let your add a node to an xml file.

    Here's the catch, I can write in an external xml file, without the need to load it, DIRECTLY through flex?

    or I have to use some php i.e. backend


    Thanks heaps!

    ojk007

    The Flash Player, when it is hosted by a browser, severely limits access to the resources of the host computer. In other words, you cannot read and write files. If the XML file resides on the server, then you can use the code server-side (e.g. PHP) and edit the file, or you can load the XML file into your Flex application on the client computer, change it, then refer to something that can write the file.

  • How to write a group with 2 parents in xml file?

    Hi all

    In my xml file, I use the following queries.

    Q1:
    Select q xxx;

    Q2:
    Select w to yyy;

    Q3:
    Select: q-: double w;

    Q3 is to get values of Q1 and Q2 and calculate some values.
    While writing a group is possible to write a group such as both parents?
    If so, what is the syntax for that?

    have you tried that?









  • Read and write XML files

    I'm working on a Flex application that will be used to save the entries concerning the manufacturing plan. I have two problems to solve:

    1 - can read an XML file to a local drive? (C:/temp/file)

    2. If the system where I call the web service is in offline mode, I have to create a local file that will be read vwhen later, that the system will be in place. How can I create a local file from Flex?

    A web-based application cannot access the local drive without the user's permission.

    Sometimes, people download local files to a server (as demanding as the user

    approval) and then request the file from the server.

    You can use local SharedObject to store data, although there are limits to

    the amount of data.

    The recommended option is to create an AIR application.  He will be able to access

    the local disk after installation.

  • Write the XML to a file. Go to BI Publisher?

    Hello!
    I posted this on the forum of the APEX, but it's really a matter of BEEP I ask would take APEX out of the picture.

    Is it possible to generate a .xml file myself, then use this file to create a BI Publisher report? I want to work around by using the APEX report query option to generate a .xml file that is used to create a BEEP report.
    Thank you
    Tammy

    Hello
    You can use the XML file that you generated as a Source.
    You must create a data source under
    Admin > file

    Create a new Data Source
    Give the name and location of the file.

    While creating a report in the Datamodel, select the Source as a FILE.

  • repair of iTunes - fusion of the xml files or combine libraries

    My iTunes xml I messed up a little bit and now all my old songs have the same Date added date, if they have been added to 4 years ago or on 02/07/15.

    Titles added after 02/07/15 have correct dates.

    I am trying to find the better (not necessarily the easiest) way to fix them.

    It is important for me because I sort my titles by date added.

    I have a huge library and can change them one by one in the xml file.

    I think that the ideal way to change the dates maybe with a script that would take the correct dates back to the old xml and replace the incorrect in the xml of the last.

    However, I do not have such a script, and I don't know how to write one.

    So my other option is to merge libraries.

    I will do this on a separate drive in order not to spoil the libraries either old or new.

    I have a bunch of backups, but had not noticed the problem posed by the until after all the backups had already been updated with new and incorrect files.

    I also have a fully functional library on a player removed from my MBP dead last year.

    So I now several copies of a messed library and an obsolete library containing the correct information.

    If I had to start with the old library I would need then to add all new titles that were added last year on my new computer.

    I can sort of filter by modification Date to clear the majority of them.

    I know that iTunes has a feature to add to the library , but before I use it I want to make sure that will accomplish what I am trying to do.

    I hope that someone with real experience in doing that reads my post.

    Useful suggestions of someone else is appreciated.

    Too bad (as if someone was actually going to answer).

    I have since discovered that the added Date cannot be changed.

    So now I have copied the old library on an external drive, made iTunes open this library, and then added everything in my current library which was not in the old library. I now have a library with the correct dates for the majority of the files, but all my files since August 2014 have now to the current Date added date.

    Better to have 16 months from the incorrect dates of 6 years.

  • How to ADD a child inside the childe in XML file

    I want to write the configuration file using the XML tools.

    in what I am facing problem to add a child next to the child.

    Please guide me to resilve this problem.

    Thank you

    Gilles Poirier

    Thank you

    I is a good Solution. Now, I try to add a new Tag, and once again in this new child.

    Thank you

    Gilles Poirier

  • The attached VI works when I run it initially to create the XML file, but by pressing once the XML file is created, it is not up-to-date. What I am doing wrong?

    The attached VI works when I run it initially to create the XML file, but when I change the data and run once the XML file is created, it is not updated with new data. What I am doing wrong?

    Thank you.

    It sounds like the logic that has been written in VI

    Internal decision of true / false:

    (file exists: false) write in the file XML, unflatten for display

    (file exists: true) read the XML file, unflatten for display

    At no time when the file exists (true case) is the XML file updated...

  • Data from the XML file in a large application...


    I don't know what question is asked.  The subject contains XML files and large scale applications, yet the last lines refer to write a Cluster in XML and seems to wonder if the Cluster must be a Global Variable or a TypeDef.

    A 'good idea' general is to create a TypeDef that specifies (or "sets") (almost) each Cluster that you create in LabVIEW.  This serves as a single-point cluster definition.  If you need to make changes, you change the TypeDef and variables based on it change to match.

    I do not understand why the Global Variables and TypeDefs are mentioned in the same sentence.

    Bob Schor

Maybe you are looking for