如何用DXL从Module2提取缺失编号补全Module1的[编号]内容?
Can I use DXL to fill missing [number] entries in Module1 with values from Module2?
Absolutely, this is totally achievable with IBM Rational DOORS DXL! Let's walk through how to build a script that handles this task smoothly.
Quick Assumptions to Start
First, I need to clarify what "corresponding position" means for your modules—for this example, I’ll go with two common scenarios you might be working with:
- Either both modules share an identical hierarchical structure (so the nth object in Module1 maps directly to the nth object in Module2)
- Or objects in both modules have a unique identifier (like a custom "ID" attribute) that lets us match them up precisely
I’ll also assume:
- Module2’s valid numbers are wrapped in square brackets (e.g.,
[123]) - Module1’s missing entries are exactly the string
[no number]
Practical DXL Script Example
Here’s a working script that implements this logic—you can tweak it to fit your exact module setup:
// Open your target modules (replace the paths with your actual module locations) Module mod1 = edit("C:/DOORS/Modules/Module1", false) Module mod2 = read("C:/DOORS/Modules/Module2", false) // Check if modules opened successfully if (null mod1 || null mod2) { print "Error: Failed to open one or both modules. Double-check the paths!\n" exit } // Loop through every object in Module1 Object obj1 for obj1 in mod1 do { string objText = obj1."Object Text" // Look for objects with the missing number placeholder if (objText contains "[no number]") { // --- Choose your matching method below --- // Option 1: Match by object position (same index in both modules) Object obj2 = object(mod2, number(obj1)) // Option 2: Match by a unique attribute (uncomment and adjust if needed) // string uniqueID = obj1."Unique ID" // Object obj2 = find(mod2, "Unique ID", uniqueID) // Skip if no matching object exists in Module2 if (null obj2) { print "Warning: No match found for object " fullName(obj1) "\n" continue } // Extract the number from Module2's object text string obj2Text = obj2."Object Text" regexp numberPattern = /\[(\d+)\]/ // Regex to capture digits inside [] if (match(numberPattern, obj2Text)) { string newNumber = "[" matchText(numberPattern, 1) "]" // Replace the placeholder with the valid number obj1."Object Text" = replace(objText, "[no number]", newNumber) print "Updated: " fullName(obj1) " → " newNumber "\n" } else { print "Warning: No valid [number] found in matching object " fullName(obj2) "\n" } } } // Save changes and clean up save(mod1) close(mod1) close(mod2) print "All updates completed!\n"
Key Tips for Customization
- Matching Logic: Pick Option 1 or 2 based on how your modules are organized. If your modules don’t align by position, the attribute-based match (Option 2) is more reliable.
- Regex Tweaks: If your numbers include letters or special characters, adjust the regex pattern. For example, use
\[([A-Za-z0-9-]+)\]to capture alphanumeric numbers with hyphens. - Test First: Always run this script on a copy of your modules before using it on production data—better safe than sorry!
- Permissions: Make sure you have edit access to Module1 and read access to Module2, otherwise the script will fail.
内容的提问来源于stack exchange,提问作者Elek.J
相关产品推荐
相关产品推荐

