General XMetaL Discussion

XMetaL Community Forum General XMetaL Discussion Document.getDocumentObject() returns Null

  • tgoglia

    Document.getDocumentObject() returns Null

    Participants 4
    Replies 5
    Last Activity 9 years, 11 months ago

    I'm working on a Java project using XMetal Developer. One task I need to do is to update an attribute of the XML file the user is editing in XMetal [its a DITA file and I need to update an othermeta content attribute]. I can access the file no problem and read its contents as a string, but I can't access the DOM tree as any and all of the DOM methods return null.

    What am I doing wrong here? Is there a method call I'm missing? Something to initialize the DOM?

    Here's the code:

    //Get a handle to the application and find open docs.
            Application xmetal = new Application();
            Documents docs = xmetal.getDocuments();
         
            //loop through open documents.
            for(int i=1;i<=docs.getCount();i++)
            {
                SQVariant var = new SQVariant(i);
                _Document doc = docs.item(var);
               
                //This outputs the expected title.
                System.out.println(doc.getTitle());
                   
                //This outputs the XML.
                //System.out.println(doc.getXml());
                   
                //This output is null.
                System.out.println(doc.getDocumentElement());
                   
            }

    Reply

    tgoglia

    Reply to: Document.getDocumentObject() returns Null

    On the chance that this issue is specific to DITA, I opened a standard XML file [no DTD] and reran my test code. The results were the same.

    One note: We're using XMetal as a content editor for the SDL Trisoft CMS.

    Reply

    Derek Read

    Reply to: Document.getDocumentObject() returns Null

    So (after our phone call and discussion with our dev team) just to be clear:

    1) You are running XMetaL Author Enterprise 6.0.1
    2) Your goal is to modify DITA documents that are already open (all APIs should work, but this is your goal).
    3) You can read values using some (possibly all) APIs except DOM-related APIs return null.
    4) You have tried other document types and they give the same results (so this is not specific to interference from the DITA customization, which makes sense as it should not interfere).

    From what I can tell, the last time we updated the JAT was probably when we released our 5.0 version. So it is most likely that the issue you are seeing is a limitation in the JAT not having been recompiled and that changes made to the COM portion of the product have affected the JAT.

    I'll have our developers check on this but I think basically what this means is that the JAT would need to be recompiled. We don't actually change APIs, but the way things are compiled for COM might break the JAT. This type of thing could easily get past our QA team as I don't believe they test with anything more than the JAT demo included with XMetaL Developer. It just includes a few calls for moving the selection around, checking which elements are allowed at a given position and inserting elements using Selection.InsertElement() (not DOM).

    Range/Selection APIs seem to be working fine so I would suggest just avoiding the DOM APIs and use other APIs for inserting elements/attributes until such time as we can release a new compile (which possibly won't come until our 8.0 release).

    Reply

    tgoglia

    Reply to: Document.getDocumentObject() returns Null

    The issue just got curiouser. The same code that didn't work last Thursday is now working. I'll let you know when/if the issue pops up again and see if I can get a handle on the circumstances.

    To those reading this because they're having a similar issue:

    One other workaround that's easy to implement but perhaps not the most efficient is to work directly with the file.

    1. Read file from disk.
    2. add the new content.
    3. Save the file back to disk.
    4. Call _Document.reload() method of XMetal API.

    Reply

    tgoglia

    Reply to: Document.getDocumentObject() returns Null

    So the problem seems related to the computer going into sleep mode. If I open a file, if I call my app right away I get a value from the call to getDocumentObject(). But if the computer goes into sleep mode and then restarts, this value is null.

    After sleeping, I tried a call to _Document.Reload() before the call to getDocumentObject(), but this causes other strange behavior: the “Choose DTD” window is opening and my application is left frozen waiting for user input.

    Reply

    Derek Read

    Reply to: Document.getDocumentObject() returns Null

    I have no idea why things would be failing when the computer sleeps. I assume you wake it up as a user by moving the mouse or by a key press?

    The fact that calling Reload() is triggering the “choose DTD” dialog means that the DTD cannot be found. The same prompt should also occur when the document is first opened. But if it doesn't then I guess your changes to the file are removing the DOCTYPE declaration or changing it after open? I'm sort of shooting in the dark here.

    Instead of calling Reload() you might wish to try Application.PostSetFocus(1). My suspicion is that putting focus back into the active document might help, though I can't say why focus is moving out of the document. Either way, calls to the ActiveDocument should function regardless of whether focus is actually in the document. These are just guesses at this point since the last thing that occurs when you call Reload() is to restore the user's selection (and therefore focus) in the document.

    Reply

  • You must be logged in to reply to this topic.

Lost Your Password?

Products
Downloads
Support