Check for the existing XML element

Hi all

I'm writing a simple script first check if an XML element exists and creating so if it's not. I tried to change a piece of code that I used previously to do the same for paragraph styles, but apparently it's not that simple. Currently, all I get is the error "Unable to run the script in the 'main' target engine!" Without checking them, adding the XML element based on the result of the search works very well.

/* Find all instances of the word "Superscript" */
app.findTextPreferences.findWhat = "Superscript";
var mySuperscript = myDocument.findText(); // Save search result for future reference

/* See if an XML element named "Superscript" already exists, and create it if that's not the case; then add it to all instances of the word "Superscript" */
var myXMLElementSuper = myDocument.xmlElements.item("Superscript");
try {
var myName = myXMLElementSuper.name;
}
catch (myError){
    var myXMLElementSuper = myDocument.xmlElements.add({markupTag:"Superscript", xmlContent:mySuperscript[i]});}

Any help would be greatly appreciated!

Regards and thanks in advance.

Julian

The myDocument.xmlElements always has a single element - the root element.

If you want your element directly below that, you have to work a level down.

To try-catch for such situations regular aid is bad because you spend so usually the ESTK option stop on exceptions and real problems don't miss. Use the isValid property.

var rootXE = myDocument.xmlElements.item(0);
var superXE = rootXE.xmlElements.itemByName("Superscript");
if( !superXE.isValid )
  superXE = rootXE.xmlElements.add(...
else
 superXE = superXE.getElements()[0]; // take first of potentially multiple elements

Tags: InDesign

Similar Questions

  • Check for the existing index

    I'm a DBA working with 3 application developers, they want to know how to check for existing indexes for some columns
    in a table in their schema.

    a friend told me to check the existing index for some column you have to query
    view dba_ind_columns so you must be a sysdba user

    but I don't want to give the developers of the application of the privilege sysdba

    but my friend told me, to avoid sysdba grant for application developers, they can query the user_indexes view in their scheme, but after watching the user_indexes view,.

    It gives me a lot of data but does not give me the NAME of COLUMN

    How can I solve this problem, which is:

    Let application developers check existing indexes for some columns in their schema without granting them sysdba privilege.

    user_ind_columns

  • How to add tags in the existing XML file?

    Hello
    I have a requirement in which I need to add a tag to the existing xml data.

    For example:
    < ROW >
    < EVNT_ID > 7333976 < / EVNT_ID >
    < DISTRCT_CD > 67 < / DISTRCT_CD >
    < TIME_OFF > 6 May 2008 10:50:04 < / TIME_OFF >
    < / ROW >

    The desired output is,

    < DI_DATA >
    < ROW >
    < EVNT_ID > 7333976 < / EVNT_ID >
    < DISTRCT_CD > 67 < / DISTRCT_CD >
    < TIME_OFF > 6 May 2008 10:50:04 < / TIME_OFF >
    < / ROW >
    < / DI_DATA >

    I must add < DI_DATA > < / DI_DATA > at the beginning and end of the entry.

    Anyone of you could help me with that?

    Thank you
    GV

    If your XML is just in a CLOB, you can just use manipulation of strings to add/add nodes on. If you have it in an XMLType you could just do the following

    select appendchildxml(XMLTYPE(''),
                                  'DI_DATA',
                                  XMLTYPE('
    7333976
    67
    06-May-2008 10:50:04 AM
    '))  -- this would be your variable
      from dual;
    

    which will put your data in the DI_DATA node.

  • How can you specify the default value for the undefined array elements

    According to aid LV, the tables have two default values, the normal default value and the default value for the undefined array elements.

    I assume that there must be a way to specify the default value for later, but I can't find it anywhere.  Any ideas?

    I know that you can drag the item out of the table container.  Change the default value on this scalar element.  Then drag the item in table tank.

  • Windows cannot check for the error code 80070424 updates.

    I have windows vista premium x 64
    Windows Update stopped working and when I they do it manually it says windows cannot check for the error code 80070424 updates.
    I searched everywhere for an answer... Please help

    ----

  • our company had Adobe CS 3, we ship adobe creative cloud member of more than 2 years now. How can I get credit for the existing customer.

    our company had Adobe CS 3, we ship adobe creative cloud member of more than 2 years now. But we must all credit for the existing customer.

    There is no current discount for loyal customers.  You must have missed the opportunity to get a discount at the end of May.  Before that if you were an owner of Creative Suite, you can get the first year at a reduced rate.

  • How to 'Allow smoothing' for the loaded XML .jpg?

    I have a thumb wheel image that loads a bunch of jpg. They are be enlarged rollover in 1,05.

    I've seen pixelated at scale 1 x 1 as well as expanded.

    I'm happy prettey how Flash renders the images with "Allow smoothing" on.

    How would I do it for the loaded xml jpg? Would it be as a script in the main folder or in the xml file?

    Here's how to load images in AS3:

    function completeHandler_AppPopUps(e:Event):void{
              //trace("thumbnail complete "+e.target.loader.parent.parent.name)//tells us when the loading is complete
    
              //size image into scroller (need only if I will have images at different sizes)
              resizeMe(e.target.loader.parent, 60, 90, true, true, false);
    
              TweenMax.to(e.target.loader.parent.parent, .5, {alpha:.7});//makes all thumb images at alpha=.7 after they are fully loaded
              //Tweener.addTween(e.target.loader.parent.parent, { alpha:1, time: .5 } );//caurina version
    
              TweenMax.to(e.target.loader.parent.parent, .5, {colorMatrixFilter:{contrast:1.1, brightness: .7, saturation: .5}});//makes all thumb images at brightness:0.5 after they are fully loaded
    
    
    }
    
    

    I don't want to complicate things more than necessary, but just in case it's needed here is the complete code for the edification of the wheel section:

    /////Parse XML
    //build scroller from xml
    function buildScroller(imageList:XMLList):void{
              trace("build Scroller");
    
              for (var item:uint = 0; item<imageList.length();item++) {
                        var thisOne:MovieClip = new MovieClip();
    
                        //outline
                         var blackBox:Sprite = new Sprite();
                        blackBox.graphics.beginFill(0xFFFFFF);
                        blackBox.graphics.drawRect(-1, -1, 62, 92);//-1,-1 places rectangle 1px left and up.62, 92 draws rectangle 1px wider on all sides of placed image dimenstions of 60x90
                        blackBox.alpha = thumbFadeOut;//setting Border Tweens
                        thisOne.addChild(blackBox);
                        thisOne.blackBox = blackBox;//setting Border Tweens
    
                          thisOne.x = thisOne.myx = (60 + padding) *item;//replaces the line above for scale tweenw roll over calculation. "myx" is a made up term which defines the position. 61 is the width of the thumb
                        thisOne.itemNum = item;
                        thisOne.title = imageList[item].attribute("title");
                        thisOne.link = imageList[item].attribute("url");
                        thisOne.src = imageList[item].attribute("src");
                        thisOne.alpha = 0;//makes all thumb images at alpha=0 before they are fully loaded
    
                        //Loading and Adding the Images
                        //image container
                        var thisThumb:MovieClip = new MovieClip();
                        //add image
                        var ldr:Loader = new Loader();
                        //var url:String = imageList[item].attribute("src");
                        var urlReq:URLRequest = new URLRequest(thisOne.src);
                        trace("loading thumbnail "+item+" into Scroller: " + thisOne.src);//url
                        ldr.load(urlReq);
                        //assign event listeners for Loader
                        ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler_AppPopUps);//tells us when the loading is complete
                        ldr.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, errorHandler_AppPopUps);//tells us if there are any typo errors when the loading is complete
                        thisThumb.addChild(ldr);
                        thisOne.addChild(thisThumb);
    
                        //create listeners for this thumb
                        thisOne.buttonMode = true;//makes boxes act as buttons
                        thisOne.addEventListener(MouseEvent.CLICK, clickScrollerItem_AppPopUps);//makes boxes act as buttons
                        thisOne.addEventListener(MouseEvent.MOUSE_OVER, overScrollerItem_AppPopUps);//traces the title when the mouse is over the bounding box in the Output Panel
                        thisOne.addEventListener(MouseEvent.MOUSE_OUT, outScrollerItem_AppPopUps);//traces the title when the mouse is out the bounding box in the Output Panel
    
    
    
                        //add item
                        scroller.addChild(thisOne);
              }
              scroller.addEventListener(Event.ENTER_FRAME, moveScrollerThumbs);//adding movement on mouse position
              trace("termination of build scroller");
    
    }
    
    
    

    in your listener to full charge, enable the property smoothing to the content of your charger (expressed as a bitmap).

    function completeHandler_AppPopUps(e:Event):void{

    Bitmap(e.currentTarget.loader.content).smoothing=true;
              //trace("thumbnail complete "+e.target.loader.parent.parent.name)//tells us when the loading is complete

    //size image into scroller (need only if I will have images at different sizes)
              resizeMe(e.target.loader.parent, 60, 90, true, true, false);

    TweenMax.to(e.target.loader.parent.parent, .5, {alpha:.7});//makes all thumb images at alpha=.7 after they are fully loaded
              //Tweener.addTween(e.target.loader.parent.parent, { alpha:1, time: .5 } );//caurina version

    TweenMax.to(e.target.loader.parent.parent, .5, {colorMatrixFilter:{contrast:1.1, brightness: .7, saturation: .5}});//makes all thumb images at brightness:0.5 after they are fully loaded

    }

  • How to check for the two first digits?

    Can someone please... There is demand to have a hidden field on the form that will be filled with data. It's going to be 6 digits long and could start with 02 or 04. I need to check on the DocReady event, for the first two digits. If the first two digits are 02, the presentation of the form will remain as it is. If the first two numbers are 04, I'll have to show two hidden subforms. Can someone please provide an explanation on how to check for the first two digits of field 6 digits and do some actions.

    Thank you very much

    No, only in the event: Exchange.

  • Problem in obtaining the root XML element. (without prefix)

    Hi all

    my xml is as below.

    < ns1:abcd >
    < ns2: a > 1 < / ns2: a >
    < ns2:b > 2 < / ns2:b >
    < / ns1:abcd >

    If I try to retrieve the value of the root of the xml document.

    Myroot node = doc.getDocumentElement ();

    String result = myroot.getNodeName ();

    My output is ns1:abcd... I want only 'abcd '...

    Also if I try to print myroot.getPrefix, myroot.getNamespaceURI... all these values are null.

    My xml will not always have the same namespaces... starting from the xml inbound I must first check for namespaces... Please give me an idea.

    I think so.. I need an evaluation space names to...

    Please help me in this regard.

    Thank you
    Sabarisri. N

    Hi Sabarisri,

    Please try the following code:

    import java.io.StringReader;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Element;
    import org.xml.sax.InputSource;
    
    public class Runner2 {
        public static void main(String[] args) {
            String xmlString =
                "" +
                "  1" +
                "  2" +
                "";
    
            try {
                InputSource is = new InputSource(new StringReader(xmlString));
                DocumentBuilder docBuilder =
                    DocumentBuilderFactory.newInstance().newDocumentBuilder();
                Document document = docBuilder.parse(is);
                Element element = document.getDocumentElement();
                System.out.println(element.getLocalName());
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    

    Kind regards
    Pino

  • Check for the required amount - point application

    Hello

    During the creation of point of Application, we get a drop down menu where we have to choose

    1 check sum required - Application level
    2 check amount required - user level
    3. check sum require - Session survey


    I'm creating an application-level element that allows to store USER_ID and ACCESS_LEVEL using the query
    «SELECT USER_ID, ACCESS_LEVEL IN FX_UID, FX_ACCESS_LEVEL FROM USERS WHERE UPPER (EMAIL_ID) =: APP_USER.»

    My question is what is the function of each of them and that will be suitable for the review above the request in the light of these values are used in the authorization of the page. If Access_level = 3, all pages are made available where as if Access_level is 1 then only read_only is enabled for the user.


    Thank you
    Shijesh

    OK, now I see what you were saying before. Then use this setting that I have described, and that should be all you need. Furthermore, your statement "select into" must reference the elements of the application as a bind variable.

    Scott

  • Check for the presence of malware

    How can I check for viruses/malware on my iMac with OS X El Capitan

    Go to http://www.etresoft.com/etrecheck , download and run EtreCheck, copy paste here the status report.  If there is any malware/adware on your system, it will appear, and then we'll tell you how to dispose of it here.

  • I also get the error code 80070005 when you try to use Windows Update to check for the updates

    I get this error code as soon as I try to check updates. It does not even say there are updates tells me to enable updates, but when I try it gives the code. I used Microsoft Fix and now it says everything is fixed and ok but it is not. So now what?

    Hello

    1. what Microsoft fixit did you run?
    2. don't you make changes to the computer before the show?

    I suggest you try the steps from the following link:

    Error: 0x80070005 when you try to install updates by using Microsoft Update or Windows Update
    http://support.Microsoft.com/kb/968003

    Note: When you perform a virus scan Malware, you will lose data that are affected by the virus. Microsoft is not responsible for the loss of this data.

  • An error occurred during the security check for the message

    Hello

    I'm just starting to try to use axis2 to access the Eloqua api webservie. Under code comes from using the API of Eloqua WS with Java - part 1 and I followed the steps in the link.

    // To debug the this line will set Log4J to use System.Out for a lot of
            // messages.
            // BasicConfigurator.configure();
            // Configure your username and password here.
            String company = "TechnologyPartnerWelocalize";
            String username = "leo.chen";
            String password = "Password1";
            // Assuming that the conf directory has the Axis2 config file and
            // Rampart is installed correctly.
            ConfigurationContext ctx = ConfigurationContextFactory
                    .createConfigurationContextFromFileSystem("D:/axis2-1.6.2/conf", null);
            EloquaStub stub = new EloquaStub(ctx,
                    "https://secure.eloqua.com/API/1.2/Service.svc");
            ServiceClient sc = stub._getServiceClient();
            Options options = sc.getOptions();
            sc.engageModule("rampart");
            options.setUserName(company + "\\" + username);
            options.setPassword(password);
            String[] assetTypes = stub.listAssetTypes(new ListAssetTypes())
                    .getListAssetTypesResult().getAssetTypes().getString();
            System.out.println("Asset Types count : " + assetTypes.length);
            for (String s : assetTypes)
            {
                System.out.println(" -> " + s);
            }
    

    But I got following error when executing code above.

    Exception in thread "main" org.apache.axis2.AxisFault: An error occurred when verifying security for the message.
     at org.apache.axis2.util.Utils.getInboundFaultFromMessageContext(Utils.java:531)
     at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:375)
     at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
     at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
     at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
     at com.eloqua.secure.api.EloquaStub.listAssetTypes(EloquaStub.java:1928)
     at com.eloqua.sample.WSConsoleClient.main(WSConsoleClient.java:42)
    

    Another problem is when I changed the chain of the company to one of the other stuff like "TechnologyPartnerWelocalize111", I get below error

    Exception in thread "main" org.apache.axis2.AxisFault: SOAP header missing
     at org.apache.rampart.handler.RampartReceiver.setFaultCodeAndThrowAxisFault(RampartReceiver.java:180)
     at org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:99)
     at org.apache.axis2.engine.Phase.invokeHandler(Phase.java:340)
     at org.apache.axis2.engine.Phase.invoke(Phase.java:313)
     at org.apache.axis2.engine.AxisEngine.invoke(AxisEngine.java:262)
     at org.apache.axis2.engine.AxisEngine.receive(AxisEngine.java:168)
     at org.apache.axis2.description.OutInAxisOperationClient.handleResponse(OutInAxisOperation.java:364)
     at org.apache.axis2.description.OutInAxisOperationClient.send(OutInAxisOperation.java:421)
     at org.apache.axis2.description.OutInAxisOperationClient.executeImpl(OutInAxisOperation.java:229)
     at org.apache.axis2.client.OperationClient.execute(OperationClient.java:165)
     at com.eloqua.secure.api.EloquaStub.listAssetTypes(EloquaStub.java:1928)
     at com.eloqua.sample.WSConsoleClient.main(WSConsoleClient.java:41)
    Caused by: org.apache.rampart.RampartException: SOAP header missing
     at org.apache.rampart.RampartEngine.process(RampartEngine.java:96)
     at org.apache.rampart.handler.RampartReceiver.invoke(RampartReceiver.java:92)
     ... 10 more
    

    I connected to the Eloqua using "leo.chen/Password1" and found that the name of the company is technology partner - Welocalize.

    No idea what causes this kind of errors? I use Axis2 - 1.6.2 and rampart - 1.6.2. What I changed so far is to copy modules of the rampart - 1.6.2 and axis2-1.6.2\repository to axis2-1.6.2\conf folder and the commented line "< Ref module ="address"/ >" in axis2.xml.

    Leo, I think that your use case law above may be met by using our RESTful API.  For more details, see REST API - Documentation for kernel objects .

    With this API, you can use OAuth instead of basic authentication, and it is probably easier to try to consume the SOAP WSDL and make it work.

  • My Mac does not read the Mac for the Adobe Photoshop elements 13 drive [was: Mac]

    My Mac does not read the Mac for the Adobe P:photoshop elements 13 drive, fresh have Costco. ???

    You can try to download instead and use the serial number, you make the acquisition of the disc...

    PES 10, 11, 12, 13 - https://helpx.adobe.com/photoshop-elements/kb/photoshop-elements-downloads.html

    You can also download the demo version of the software through the page linked below and then use your current serial number to activate it.

    Don't forget to follow the steps described in the Note: very important Instructions in the section on the pages of this site download and have cookies turned on in your browser, otherwise the download will not work correctly.

    Photoshop/Premiere Elements 13: http://prodesigntools.com/photoshop-elements-13-direct-download-links-premiere.html

  • How to bulk to check for the import?

    I'm new to LR and am importing photographs from a master file disk.  Is there a way to bulk select for import, without using the audit of all the / check option no or checking them one at a time?  For example, I want to import 100 to 200 photos in a folder.  How can I bulk check the 100 without having to do them one at a time? I would normally expect a selected choice of context for "check images", but I don't see that anywhere.

    Select the first. SHIFT selects the last. Hit the SPACEBAR to check all the.

Maybe you are looking for