【问题标题】:How to get object and lower hierarchical objects from a DXL如何从 DXL 中获取对象和较低层次的对象
【发布时间】:2019-07-02 15:01:19
【问题描述】:

我是 DXL 的新手,正在做一些可能很简单的事情。 我想解析当前模块,并为每个具有给定 ID(在下面调用 IDNUM)不为空的对象获取以下数据: IDNUM - 对象文本 - 具有较低层次级别的所有文本,并且对于所有喜欢此对象的对象都是相同的。

使用代码可能更容易理解。到目前为止,它看起来像这样:

Object o 
Object ol
Link l
Module m = current Module

For o in entire(m) do{
 if (o."IDNUM" != ""){
   print o."IDNUM" "" 
   print o."text" "" 
   //HERE I WOULD LIKE TO ALSO PRINT EVERY TEXT IN OBJECT "LOWER" THAN o
   for l in o --> "*" do{
    ol = target(l)
    print ol."text" "" 
    //HERE I WOULD LIKE TO ALSO PRINT EVERY TEXT IN OBJECT "LOWER" THAN ol
   }
  }
}

基本上,我有一个对象和喜欢它的对象的 ID 和标题,但没有下面的文本。换句话说,我的代码将“模仿”函数right click>copy>copy with hierarchy 我怎样才能做到这一点?不幸的是,我没有发现任何有用的东西。

非常感谢,

【问题讨论】:

    标签: ibm-doors


    【解决方案1】:

    这是您概述的草图代码:

    Object o 
    Object ol
    Link l
    Module m = current Module
    
    For o in entire(m) do{
     if (o."IDNUM" != ""){
       print o."IDNUM" "" 
       print o."text" "" 
       //HERE I WOULD LIKE TO ALSO PRINT EVERY TEXT IN OBJECT "LOWER" THAN o
       for l in o --> "*" do{
        ol = target(l)
        print ol."text" "" 
        //HERE I WOULD LIKE TO ALSO PRINT EVERY TEXT IN OBJECT "LOWER" THAN ol
       }
      }
    }
    

    这里有一些小的语法需要更改,但最大的更改是您处理链接项目的方式。链接“活”在源模块中,但它们只存储有限数量的信息,主要是链接的源模块和目标模块,以及它们接触的对象的绝对数量。因此,在尝试从中读取文本之前,您需要检查另一侧的模块是否已打开。

    而且由于您要尝试遍历整个链接结构,因此您需要一个递归元素。

    我可能会得到这样的结果:

    //turn off run limit timer- this might take a bit
    pragma runLim , 0 
    
    Object o 
    Module m = current Module
    
    // Recursive function- assumes each object has a text attribute- will error otherwise
    void link_print(Object obj) {
        print obj."text" "\n"
        Link out_link
        Object next_obj = null
        for out_link in obj -> "*" do {
            // Set the next object in the chain
            next_obj = target ( out_link )
            // This might return null if the module is not loaded
            if ( null next_obj ) {
                // Load the module in read-only mode, displayed and in standard view
                read ( fullName ( ModName_ target ( out_link ) ) , true , true )
                // Try and resolve out 'target' again
                next_obj = target ( out_link )
                // If it doesn't work, print a message so we can figure it out
                if ( null next_obj ) {
                    print "Error Accessing Object " ( targetAbsNo ( out_link ) )""
                } else {
                    //Iterate down structure
                    link_print ( next_obj )
                }
            } else {
                //Iterate down structure
                link_print ( next_obj )
            }
        }
    }
    
    
    for o in entire(m) do {
        // Note that I cast the result of o."IDNUM" to a string type by appending ""
        if (o."IDNUM" "" != ""){
            print o."IDNUM" "\n" 
            // Recurse
            link_print(o)
            print "\n"
        }
    }
    

    注意!根据您的链接结构的大小,即您有多少级别(以及是否有任何循环链接模式),这可能是一项非常耗费资源的任务,并且使用“打印”命令以外的其他东西会更好地解决(比如例如,将它附加到一个 word 文件中,这样你就知道它在出错之前走了多远)

    祝你好运!

    编辑:

    这个脚本现在将进入一个单层,而不是递归地向下,但应该报告子对象。

     //turn off run limit timer- this might take a bit
    pragma runLim , 0 
    
    Object o 
    Module m = current Module
    
    // Recursive function- assumes each object has a text attribute- will error otherwise
    void link_print(Object obj) {
        print obj."text" "\n"
        Link out_link
        Object next_obj = null
        Object child_obj = null
        for out_link in obj -> "*" do {
            // Set the next object in the chain
            next_obj = target ( out_link )
            // This might return null if the module is not loaded
            if ( null next_obj ) {
                // Load the module in read-only mode, displayed and in standard view
                read ( fullName ( ModName_ target ( out_link ) ) , true , true )
                // Try and resolve out 'target' again
                next_obj = target ( out_link )
                // If it doesn't work, print a message so we can figure it out
                if ( null next_obj ) {
                    print "Error Accessing Object " ( targetAbsNo ( out_link ) )""
                } else {
                    // Loop and report on child objects
                    for child_obj in next_obj do {
                        print child_obj."text" "\n"
                    }
                }
            } else {
                // Loop and report on child objects
                for child_obj in next_obj do {
                    print child_obj."text" "\n"
                }
            }
        }
    }
    
    
    for o in entire(m) do {
        // Note that I cast the result of o."IDNUM" to a string type by appending ""
        if (o."IDNUM" "" != ""){
            print o."IDNUM" "\n" 
            // Recurse
            link_print(o)
            print "\n"
        }
    }
    

    【讨论】:

    • 非常感谢您的回答。我会尽快尝试使用它并让您知道它是否有效。但它看起来很有希望 PS:是的,“打印”命令放在这里只是为了强调我想要提取的内容。以后我会想办法写入word/记事本文件……
    【解决方案2】:

    亲爱的拉塞尔(和其他所有人)

    我刚刚浏览了您提供给我的一段代码,它可以工作....但不是我要找的。看来我的解释不是很清楚。对不起(我不是母语人士)。 我不想获取所有链接,而只是写在当前链接指向的对象下方的Object text。 这是我的文件的样子

     object1 (with IDNUM) : "Title_doc_1"   --> (link) objectA "Title_doc_2"
        object2 : "some_text"                            objectB : "some_text"
        object3 : "some_text"                            objectC : "some_text"
    

    object1 可以指向许多其他objectA,但我已经处理了。)

    我上面提供的代码解析“doc_1”,并打印"IDNUM" "Title_doc_1" "Title_doc_2"

    我正在寻找的不仅是objectA,还有objectBobjectC,它们在层次上低于objectA(以及object2object3,但它会相同过程)。

    跳跃我让自己明白了......

    【讨论】:

    • 啊,我明白了!将编辑我的答案。您正在寻找链接项目的每个“子”对象。
    • 我将您的 aswer 中的内容与 level(o) 一起使用,并且效果很好。非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-28
    • 2022-01-25
    • 1970-01-01
    • 2010-11-17
    • 2010-11-23
    相关资源
    最近更新 更多