Hi, oleMethod(oleDomDocument, "LoadXML", argAutoArgs, blnResult )
It is able to load some xml files, but the one i want leads to an error. string dbeATPFile = get dbeATPFile print "reading input xml file into a stream\n" Stream input = read dbeATPFile //ConfStream input = confRead path //print "after confread\n" Buffer stringXML = create string str while (true) { input >> str print ""str"\n" if (end of input) break stringXML += str } print "Finished reading input xml file into a buffer\n" oleDomDocument= oleCreateAutoObject("MSXML.DOMDocument") if(oleDomDocument==null) { ack("On this system the ActiveX class \"MSXML.DOMDocument\" is not registered") } bool blnResult = false OleAutoArgs argAutoArgs = create put(argAutoArgs, stringXML"") oleMethod(oleDomDocument, "LoadXML", argAutoArgs, blnResult ) My xml file: <?xml version="1.0" encoding="utf-8"?> <testcampaign version="7/22/2016 - 10:52:32 AM"> <testcase id="TC1465391205" name="Login as root" tcAttribute="Setup" description="Login as root, as it is required for some operations." csv_file_path="" more_attempts="False" recovery_fct_lib="" recovery_fct_name="" clean_recovery_fct_lib="" clean_recovery_fct_name=""> </testcampaign> </testcase>
I would be glad if some one could help me out srikk.p - Tue Aug 09 23:31:04 EDT 2016 |
Re: XML import to DOORS using xml are you sure that you posted your xml file correctly? /testcampaign and /testcase need to switch places |
Re: XML import to DOORS using xml Mike.Scharnow - Wed Aug 10 07:15:28 EDT 2016 are you sure that you posted your xml file correctly? /testcampaign and /testcase need to switch places Mike, yes that was a copy paste mistake. But that was not the reason what led to the problem i mentioned. Meanwhile i got the problem solved. Two things led to the problem of the xml file not getting imported. 1. BOM characters at the beginning of the xml file. I have removed them as the encoding is utf-8 and hence the BOM characters might not be necessary. Could any one confirm this? I am not done with my programming yet, but atleast i can import and read all the tags as of now, so it seems to be working without the BOM characters. 2. There was no new line character after the last closing tag. In the posted xml, after </testcampaign> (after we switch the </testcampaign> and </testcase> ) So after doing the above 2 steps the import worked.
I have one more question: For importing xml, into a module using dxl i have observed 3 methods: 1. Read into a Buffer using "read" and then parse the buffer to get each tag, its attribute, attribute value etc... (straightforward, a little more work without any DOM APIs) 2. Using the perms mentioned in the dxl standard library by Mathias Mamsch - oleCreateAutoObject, oleMethod (to loadxml), oleGet(documentelement), oleGet(selectnodes) .... 3. I have also found a post which mentions perms like
"DOM_Document_ parseXMLBuffer_ (Buffer)
The first method is clear to me. Could any one tell me whats the difference between 2 and 3. I am currently following method 2. But i am just interested to know the difference.
Thank you
|
Re: XML import to DOORS using xml srikk.p - Thu Aug 11 05:30:33 EDT 2016 Mike, yes that was a copy paste mistake. But that was not the reason what led to the problem i mentioned. Meanwhile i got the problem solved. Two things led to the problem of the xml file not getting imported. 1. BOM characters at the beginning of the xml file. I have removed them as the encoding is utf-8 and hence the BOM characters might not be necessary. Could any one confirm this? I am not done with my programming yet, but atleast i can import and read all the tags as of now, so it seems to be working without the BOM characters. 2. There was no new line character after the last closing tag. In the posted xml, after </testcampaign> (after we switch the </testcampaign> and </testcase> ) So after doing the above 2 steps the import worked.
I have one more question: For importing xml, into a module using dxl i have observed 3 methods: 1. Read into a Buffer using "read" and then parse the buffer to get each tag, its attribute, attribute value etc... (straightforward, a little more work without any DOM APIs) 2. Using the perms mentioned in the dxl standard library by Mathias Mamsch - oleCreateAutoObject, oleMethod (to loadxml), oleGet(documentelement), oleGet(selectnodes) .... 3. I have also found a post which mentions perms like
"DOM_Document_ parseXMLBuffer_ (Buffer)
The first method is clear to me. Could any one tell me whats the difference between 2 and 3. I am currently following method 2. But i am just interested to know the difference.
Thank you
1. Can anyone answer my above question?
i have one more question. hopefully some one knows the answer: 2. I have a dxl script to import xml into a DOORS module. i have created a list using (i am using this list to update the status of the script to the user) string strarrValues[] = { " " } dbeTestimportStatus = list(dbmoduleMainGUI,"Status:",450,10,strarrValues,1)
and i am updating the list at different stages of the script using following lines
int intNoLinesInStatus=noElems(dbeTestimportStatus) insert(dbeTestimportStatus,intNoLinesInStatus,"some message here...") realize(dbmoduleMainGUI) My problem is that the status is getting updated only at the end of the script (i think at the very end when the script is terminated)
Thanks Srik |
Re: XML import to DOORS using xml srikk.p - Tue Aug 23 01:33:34 EDT 2016 1. Can anyone answer my above question?
i have one more question. hopefully some one knows the answer: 2. I have a dxl script to import xml into a DOORS module. i have created a list using (i am using this list to update the status of the script to the user) string strarrValues[] = { " " } dbeTestimportStatus = list(dbmoduleMainGUI,"Status:",450,10,strarrValues,1)
and i am updating the list at different stages of the script using following lines
int intNoLinesInStatus=noElems(dbeTestimportStatus) insert(dbeTestimportStatus,intNoLinesInStatus,"some message here...") realize(dbmoduleMainGUI) My problem is that the status is getting updated only at the end of the script (i think at the very end when the script is terminated)
Thanks Srik To your first question: Option 2 uses the Microsoft XML library to parse your XML (that's why it uses oleCreateAutoObject, that is being used to communicate with other applications, like excel and word, or in this case the MSXML library).
Option 3 uses the DXL inbuild xml parser to parse your file. How that one handles xml internally I can't tell you, but this is how you use it: Stream input = read "D:/test2.xml"; Buffer stringXML = create; string str; while (true) { input >> str; stringXML += str; if (end of input) break; } DOM_Document_ domDoc = parseXMLBuffer_(stringXML); DOM_Element_ domRoot = getDocumentElement_(domDoc); DOM_Element_ domLoop; for domLoop in domRoot do{ string szTag = getElementName_(domLoop); string szText = getElementText_(domLoop); string szAttr = ""; if(hasAttribute_(domLoop, "additional")){ szAttr = getStringAttribute_(domLoop, "additional"); } print "Tag: "szTag" - Text: "szText" - Additional:"szAttr"\n"; if(hasChildElements_(domLoop)){ DOM_Element_ domChildLoop; print "Children:\n"; int i = 1; for domChildLoop in domLoop do{ print i"\n"; i++; } } } (quickly created example, it's missing stuff like deleting the buffer/closing the stream etc) Try it with this xml: <?xml version="1.0" encoding="UTF-8"?> <root> <Test>Text</Test> <Test2 additional="2">Text222</Test2> <Test3>Text321</Test3> <Test4 additional="ok"> <child></child> <child2></child2> <child3></child3> <child4></child4> </Test4> </root> To see how it works. The for-loop can be used on any dom-element to loop through all its children recursively. (Also your issue above with the missing newline at the end of the file was because you are not appending the last line in your while(true) loop, you basically skipped the closing tag. Appending the newline just made you skip the newline instead, so it works)
To your second question I'd need to see more code. You are adding to the list correctly, but seeing you are calling realize() after doing so makes me believe you are doing it somewhere where you shouldn't. I'd need to see more, especially where you are adding to the list. If you do it within a button (not apply-button) callback, you should be fine. |
Re: XML import to DOORS using xml O.Wilkop - Tue Aug 23 06:31:36 EDT 2016 To your first question: Option 2 uses the Microsoft XML library to parse your XML (that's why it uses oleCreateAutoObject, that is being used to communicate with other applications, like excel and word, or in this case the MSXML library).
Option 3 uses the DXL inbuild xml parser to parse your file. How that one handles xml internally I can't tell you, but this is how you use it: Stream input = read "D:/test2.xml"; Buffer stringXML = create; string str; while (true) { input >> str; stringXML += str; if (end of input) break; } DOM_Document_ domDoc = parseXMLBuffer_(stringXML); DOM_Element_ domRoot = getDocumentElement_(domDoc); DOM_Element_ domLoop; for domLoop in domRoot do{ string szTag = getElementName_(domLoop); string szText = getElementText_(domLoop); string szAttr = ""; if(hasAttribute_(domLoop, "additional")){ szAttr = getStringAttribute_(domLoop, "additional"); } print "Tag: "szTag" - Text: "szText" - Additional:"szAttr"\n"; if(hasChildElements_(domLoop)){ DOM_Element_ domChildLoop; print "Children:\n"; int i = 1; for domChildLoop in domLoop do{ print i"\n"; i++; } } } (quickly created example, it's missing stuff like deleting the buffer/closing the stream etc) Try it with this xml: <?xml version="1.0" encoding="UTF-8"?> <root> <Test>Text</Test> <Test2 additional="2">Text222</Test2> <Test3>Text321</Test3> <Test4 additional="ok"> <child></child> <child2></child2> <child3></child3> <child4></child4> </Test4> </root> To see how it works. The for-loop can be used on any dom-element to loop through all its children recursively. (Also your issue above with the missing newline at the end of the file was because you are not appending the last line in your while(true) loop, you basically skipped the closing tag. Appending the newline just made you skip the newline instead, so it works)
To your second question I'd need to see more code. You are adding to the list correctly, but seeing you are calling realize() after doing so makes me believe you are doing it somewhere where you shouldn't. I'd need to see more, especially where you are adding to the list. If you do it within a button (not apply-button) callback, you should be fine. Thanks a lot for your reply, that cleared a few things. Now i understand that i am using the Microsoft XML library (oleCreateAutoObject(..) and not the DXL inbuilt XML library.
To my question of the list being not realized/updated properly, i am posting more code, hope this helps. Otherwise i would post the complete script: //GUI part dbmoduleMainGUI= create "Testspec Import" dbeTestFileLabel=label(dbmoduleMainGUI,"ATP Test file: ") //dbeTestFileLabel->"top"->"spaced"->dbeBeschreibung dbeTestFileLabel->"top"->"flush" dbeTestFileLabel->"left"->"form" dbeTestFileLabel->"right"->"unattached" dbeTestFileLabel->"bottom"->"unattached" dbeATPFileBrowsebutton = fileName (dbmoduleMainGUI,"","*.xml","ATP XML-Files") dbeATPFileBrowsebutton ->"top"->"aligned"-> dbeTestFileLabel dbeATPFileBrowsebutton ->"left"->"spaced"-> dbeTestFileLabel dbeATPFileBrowsebutton ->"right"->"unattached" dbeATPFileBrowsebutton ->"bottom"->"unattached" dbeModuleLabel = label(dbmoduleMainGUI,"Testspec Module: "); dbeModuleLabel->"top"->"spaced"->dbeATPFileBrowsebutton dbeModuleLabel->"left"->"form" dbeModuleLabel->"right"->"unattached" dbeModuleLabel->"bottom"->"unattached" d beModuleDisplayField = field(dbmoduleMainGUI,"","",40,false) dbeModuleDisplayField->"top"->"spaced"->dbeATPFileBrowsebutton dbeModuleDisplayField->"left"->"spaced"->dbeModuleLabel dbeModuleDisplayField->"right"->"unattached" dbeModuleDisplayField->"bottom"->"unattached" dbeModuleButton=button(dbmoduleMainGUI,"Browse...",function_ModuleBrowsebuttonPressed) dbeModuleButton->"top"->"spaced"->dbeATPFileBrowsebutton dbeModuleButton->"left"->"spaced"->dbeModuleDisplayField dbeModuleButton->"right"->"unattached" dbeModuleButton->"bottom"->"unattached" string strarrValues[] = { " " } dbeTestimportStatus = list(dbmoduleMainGUI,"Status:",450,10,strarrValues,1) dbeTestimportStatus->"top"->"spaced"->dbeModuleDisplayField dbeTestimportStatus->"left"->"form" dbeTestimportStatus->"right"->"unattached" dbeTestimportStatus->"bottom"->"form" apply(dbmoduleMainGUI,"Start import",function_StartimportPressed) setCenteredSize(dbmoduleMainGUI, 500, 350) realize(dbmoduleMainGUI) set(dbeATPFileBrowsebutton ,function_ATPFileBrowsebutton) show(dbmoduleMainGUI) //GUI part //callback for startimport button void function_StartimportPressed(DB x) { int intNoLinesInStatus string testspec_module bool blnModuleExists Module m string errString //clearstatus() //int intNoLinesInStatus /*******************************here is where i am trying to update the list*********************/ intNoLinesInStatus=noElems(dbeTestimportStatus) insert(dbeTestimportStatus,intNoLinesInStatus,"fasfdsdfasdf") realize(dbmoduleMainGUI) /********************************"setstatus" function contains the same above lines, just tried two different ways of updating the list********************/ //setstatus("Starting import") //ack "check" //create the test specification module testspec_module = get dbeModuleDisplayField setstatus("Creating module "testspec_module"") blnModuleExists= exists module (testspec_module) if (blnModuleExists) { softDelete(module(testspec_module)) hardDelete(module(testspec_module)) } errString = create (testspec_module,"Test specification","",1,m) if (!null errString) { warningBox errString } if (! exists module testspec_module) { ack "Module "testspec_module" could not be created. exiting.." setstatus("Creating module "testspec_module" failed. exiting..") halt } else { setstatus("Creating module "testspec_module" done..") } setstatus("Reading input xml file..") //string ATPFileName_string = get dbeATPFileBrowsebutton Stream input = read ATPFilePath Buffer stringXML = create string str while (true) { input >> str if (end of input) break stringXML += str } oleDomDocument= oleCreateAutoObject("MSXML.DOMDocument") if(oleDomDocument==null) { ack("On this system the ActiveX class \"MSXML.DOMDocument\" is not registered. exiting..") halt } bool blnResult = false OleAutoArgs argAutoArgs = create put(argAutoArgs, stringXML"") oleMethod(oleDomDocument, "LoadXML", argAutoArgs, blnResult ) if(!blnResult ) { ack "oleMethod(LoadXML) failed..\n" } else { setstatus("Reading input xml file done..") } oleGet(oleDomDocument,"documentElement",oleDocumentElement) if(oleDocumentElement == null) { ack "document element extraction failed. exiting.." halt } //get all testcases OleAutoArgs argAutoArgs1 = create put(argAutoArgs1 , "//testcase") OleAutoObj testcaseslist= null oleMethod(oleDocumentElement, "selectNodes", argAutoArgs1 , testcaseslist) int nrtestcases=0 oleGet(testcaseslist, "length", nrtestcases) parsetestcaseslist(testcaseslist, nrtestcases, m, testspec_module"") save(m) close(m) setstatus("Testcases imported to DOORS...") setstatus("DONE...") } //Callback for start import button |
Re: XML import to DOORS using xml srikk.p - Tue Aug 23 06:56:13 EDT 2016 Thanks a lot for your reply, that cleared a few things. Now i understand that i am using the Microsoft XML library (oleCreateAutoObject(..) and not the DXL inbuilt XML library.
To my question of the list being not realized/updated properly, i am posting more code, hope this helps. Otherwise i would post the complete script: //GUI part dbmoduleMainGUI= create "Testspec Import" dbeTestFileLabel=label(dbmoduleMainGUI,"ATP Test file: ") //dbeTestFileLabel->"top"->"spaced"->dbeBeschreibung dbeTestFileLabel->"top"->"flush" dbeTestFileLabel->"left"->"form" dbeTestFileLabel->"right"->"unattached" dbeTestFileLabel->"bottom"->"unattached" dbeATPFileBrowsebutton = fileName (dbmoduleMainGUI,"","*.xml","ATP XML-Files") dbeATPFileBrowsebutton ->"top"->"aligned"-> dbeTestFileLabel dbeATPFileBrowsebutton ->"left"->"spaced"-> dbeTestFileLabel dbeATPFileBrowsebutton ->"right"->"unattached" dbeATPFileBrowsebutton ->"bottom"->"unattached" dbeModuleLabel = label(dbmoduleMainGUI,"Testspec Module: "); dbeModuleLabel->"top"->"spaced"->dbeATPFileBrowsebutton dbeModuleLabel->"left"->"form" dbeModuleLabel->"right"->"unattached" dbeModuleLabel->"bottom"->"unattached" d beModuleDisplayField = field(dbmoduleMainGUI,"","",40,false) dbeModuleDisplayField->"top"->"spaced"->dbeATPFileBrowsebutton dbeModuleDisplayField->"left"->"spaced"->dbeModuleLabel dbeModuleDisplayField->"right"->"unattached" dbeModuleDisplayField->"bottom"->"unattached" dbeModuleButton=button(dbmoduleMainGUI,"Browse...",function_ModuleBrowsebuttonPressed) dbeModuleButton->"top"->"spaced"->dbeATPFileBrowsebutton dbeModuleButton->"left"->"spaced"->dbeModuleDisplayField dbeModuleButton->"right"->"unattached" dbeModuleButton->"bottom"->"unattached" string strarrValues[] = { " " } dbeTestimportStatus = list(dbmoduleMainGUI,"Status:",450,10,strarrValues,1) dbeTestimportStatus->"top"->"spaced"->dbeModuleDisplayField dbeTestimportStatus->"left"->"form" dbeTestimportStatus->"right"->"unattached" dbeTestimportStatus->"bottom"->"form" apply(dbmoduleMainGUI,"Start import",function_StartimportPressed) setCenteredSize(dbmoduleMainGUI, 500, 350) realize(dbmoduleMainGUI) set(dbeATPFileBrowsebutton ,function_ATPFileBrowsebutton) show(dbmoduleMainGUI) //GUI part //callback for startimport button void function_StartimportPressed(DB x) { int intNoLinesInStatus string testspec_module bool blnModuleExists Module m string errString //clearstatus() //int intNoLinesInStatus /*******************************here is where i am trying to update the list*********************/ intNoLinesInStatus=noElems(dbeTestimportStatus) insert(dbeTestimportStatus,intNoLinesInStatus,"fasfdsdfasdf") realize(dbmoduleMainGUI) /********************************"setstatus" function contains the same above lines, just tried two different ways of updating the list********************/ //setstatus("Starting import") //ack "check" //create the test specification module testspec_module = get dbeModuleDisplayField setstatus("Creating module "testspec_module"") blnModuleExists= exists module (testspec_module) if (blnModuleExists) { softDelete(module(testspec_module)) hardDelete(module(testspec_module)) } errString = create (testspec_module,"Test specification","",1,m) if (!null errString) { warningBox errString } if (! exists module testspec_module) { ack "Module "testspec_module" could not be created. exiting.." setstatus("Creating module "testspec_module" failed. exiting..") halt } else { setstatus("Creating module "testspec_module" done..") } setstatus("Reading input xml file..") //string ATPFileName_string = get dbeATPFileBrowsebutton Stream input = read ATPFilePath Buffer stringXML = create string str while (true) { input >> str if (end of input) break stringXML += str } oleDomDocument= oleCreateAutoObject("MSXML.DOMDocument") if(oleDomDocument==null) { ack("On this system the ActiveX class \"MSXML.DOMDocument\" is not registered. exiting..") halt } bool blnResult = false OleAutoArgs argAutoArgs = create put(argAutoArgs, stringXML"") oleMethod(oleDomDocument, "LoadXML", argAutoArgs, blnResult ) if(!blnResult ) { ack "oleMethod(LoadXML) failed..\n" } else { setstatus("Reading input xml file done..") } oleGet(oleDomDocument,"documentElement",oleDocumentElement) if(oleDocumentElement == null) { ack "document element extraction failed. exiting.." halt } //get all testcases OleAutoArgs argAutoArgs1 = create put(argAutoArgs1 , "//testcase") OleAutoObj testcaseslist= null oleMethod(oleDocumentElement, "selectNodes", argAutoArgs1 , testcaseslist) int nrtestcases=0 oleGet(testcaseslist, "length", nrtestcases) parsetestcaseslist(testcaseslist, nrtestcases, m, testspec_module"") save(m) close(m) setstatus("Testcases imported to DOORS...") setstatus("DONE...") } //Callback for start import button Instead of using "apply(dbmoduleMainGUI,"Start import",function_StartimportPressed)" try using "button(dbmoduleMainGUI, "Start Import", function_StartimportPressed)" instead and change the parameter in the function_StartimportPressed() from DB to DBE.
Apply buttons automatically close the DB upon end, buttons don't.
If you want to use the list to show the progress of the import, you should consider using a progressbar instead. DOORS doesn't allow you to use multithreading, which means that the GUI locks up during execution of the button/apply callback. You won't see the result (the adding of elements to the list) until the function is complete. The progressbar is the closest you will get to a "multithreaded solution", as it allows you to update the progressbar-GUI during runtime (show progress and messages, as well as react to the built-in "stop" button of the progress bar). |
Re: XML import to DOORS using xml O.Wilkop - Tue Aug 23 07:45:37 EDT 2016 Instead of using "apply(dbmoduleMainGUI,"Start import",function_StartimportPressed)" try using "button(dbmoduleMainGUI, "Start Import", function_StartimportPressed)" instead and change the parameter in the function_StartimportPressed() from DB to DBE.
Apply buttons automatically close the DB upon end, buttons don't.
If you want to use the list to show the progress of the import, you should consider using a progressbar instead. DOORS doesn't allow you to use multithreading, which means that the GUI locks up during execution of the button/apply callback. You won't see the result (the adding of elements to the list) until the function is complete. The progressbar is the closest you will get to a "multithreaded solution", as it allows you to update the progressbar-GUI during runtime (show progress and messages, as well as react to the built-in "stop" button of the progress bar). Thank you again. That helped me. Just one last question. I have successfully imported the xml file (which is the testspecification generated by a test tool). When we use an other test tool, the structure of the xml file changes. I wont be able to use my script to import this new xml file without making changes in the script.
Do you or anyone has any ideas how i can achieve this (importing a new xml with a different structure) without making changes in the dxl script. I am currently looking into xslt to transorm the new xml into an xml that the dxl scripts accepts/excepts. If any one has already done this, i would be glad if i could get some ideas.
I think the native xml parser (i have read somewhere that something like that exists) should be able to import different xml files, so i think this should be some how possible.
Thank you. |
Re: XML import to DOORS using xml srikk.p - Tue Aug 23 10:55:54 EDT 2016 Thank you again. That helped me. Just one last question. I have successfully imported the xml file (which is the testspecification generated by a test tool). When we use an other test tool, the structure of the xml file changes. I wont be able to use my script to import this new xml file without making changes in the script.
Do you or anyone has any ideas how i can achieve this (importing a new xml with a different structure) without making changes in the dxl script. I am currently looking into xslt to transorm the new xml into an xml that the dxl scripts accepts/excepts. If any one has already done this, i would be glad if i could get some ideas.
I think the native xml parser (i have read somewhere that something like that exists) should be able to import different xml files, so i think this should be some how possible.
Thank you. Your only two choices are to either have the .dxl script be able to identify which .xml it is importing, by for example checking the name of the root-tag or some attribute within the xml and then executing the correct import procedure, or to use a xslt to transform your .xml into a single format that can be "understood" by your importer.
XSLT is immensely powerful and a programming language in itself. That being said, if you have never before created a xslt you might feel overwhelmed with the syntax (depending on how complex of a transformation you want to achieve). I suggest you google for a few xslt examples and see how it works.
Which of the two options you chose depends on the complexity of your .xml files. If they are already somewhat similar and only differ in tag names or simple structures, feel free to use a xslt to solve the issue. If they are however very different from each other, to the point where they maybe contain wildly different concepts/attributes/hierarchy, it might be easier to create two import functions. |
Re: XML import to DOORS using xml I think i will go the xslt way of transforming any new xml to a template that is suitable for my dxl script. That way i need not change the dxl scripts each time we have a new xml. Ofcourse, when we do have a new xml, we have to write an transformation file (xslt) once. But atleast this way, the dxl scripts could remain untouched. |
Re: XML import to DOORS using xml hello, I'm trying to import the xml file into DOORS as i'm new to work in the DOORS tool, I don't have any script also I don't know the options in the DOORS to import the xml file . Hope you guys have the script to import xml file into DOORS, so it would be great help if you share the code with me .
|