Given the following simple XML file (an XMI model file, attached, TraceabilityTest.uml), I am having issues with the carriage returns embedded in the parsed doc/element that gets returned:
<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="20131001" xmlns:xmi="
http://www.omg.org/spec/XMI/20131001" xmlns:uml="
http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_kcCPIJEFEeiFAJhXHte-Tg" name="TraceabilityTest">
<packageImport xmi:type="uml:PackageImport" xmi:id="_kgyzUJEFEeiFAJhXHte-Tg">
<importedPackage xmi:type="uml:Model" href="pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0"/>
</packageImport>
<packagedElement xmi:type="uml:Package" xmi:id="_pRVKIJEFEeiFAJhXHte-Tg" name="PackageA">
<packagedElement xmi:type="uml:Package" xmi:id="_2_Y1kJEFEeiFAJhXHte-Tg" name="PackageA1">
<packagedElement xmi:type="uml:Package" xmi:id="_6sFw0JEFEeiFAJhXHte-Tg" name="PackageA1a">
<packagedElement xmi:type="uml:Class" xmi:id="_-UeMwJEFEeiFAJhXHte-Tg" name="Foo"/>
</packagedElement>
</packagedElement>
</packagedElement>
<packagedElement xmi:type="uml:Package" xmi:id="_xepw4JEFEeiFAJhXHte-Tg" name="PackageB"/>
<packagedElement xmi:type="uml:Package" xmi:id="_0etokJEFEeiFAJhXHte-Tg" name="PackageC"/>
</uml:Model>
I read the above with load_structure, and then asserted it as traceTest(Doc):
load_traceTest(Doc):-load_structure('C:..path to TraceabilityTest..\\TraceabilityTest.uml',Doc,[]),assertz(traceTest(Doc)).
Here is the prolog [Doc] that gets returned:
Doc = [element('uml:Model', ['xmi:version'='20131001', 'xmlns:xmi'='
http://www.omg.org/spec/XMI/20131001', 'xmlns:uml'='
http://www.eclipse.org/uml2/5.0.0/UML', 'xmi:id'='_kcCPIJEFEeiFAJhXHte-Tg', name='TraceabilityTest'], ['\n ', element(packageImport, ['xmi:type'='uml:PackageImport', 'xmi:id'='_kgyzUJEFEeiFAJhXHte-Tg'], ['\n ', element(importedPackage, ['xmi:type'='uml:Model', href='pathmap://UML_LIBRARIES/UMLPrimitiveTypes.library.uml#_0'], []), '\n ']), '\n ', element(packagedElement, ['xmi:type'='uml:Package', 'xmi:id'='_pRVKIJEFEeiFAJhXHte-Tg', name='PackageA'], ['\n ', element(packagedElement, ['xmi:type'='uml:Package', 'xmi:id'='_2_Y1kJEFEeiFAJhXHte-Tg', name='PackageA1'], ['\n ', element(packagedElement, ['xmi:type'='uml:Package', 'xmi:id'='_6sFw0JEFEeiFAJhXHte-Tg', name='PackageA1a'], ['\n ', element(packagedElement, ['xmi:type'='uml:Class', 'xmi:id'='_-UeMwJEFEeiFAJhXHte-Tg', name='Foo'], []), '\n ']), '\n ']), '\n ']), '\n ', element(packagedElement, ['xmi:type'='uml:Package', 'xmi:id'='_xepw4JEFEeiFAJhXHte-Tg', name='PackageB'], []), '\n ', element(packagedElement, ['xmi:type'='uml:Package', 'xmi:id'='_0etokJEFEeiFAJhXHte-Tg', name='PackageC'], []), '\n'])].
How do I get rid of the carriage returns? I have tried load_structure('TraceabilityTest,Doc,[space(remove)] and space(default), but the results seem to be the same. The carriage returns (\n) make it somewhat difficult to process the elements and their children.
I have created two utility predicates, starts_with_return/1 and remove_whitespace/2 (misnamed for now) as follows:
starts_with_return(Atom) :- atom(Atom),sub_atom(Atom,0,1,_,'\n').
remove_whitespace(L,M):-rem_ws_acc(L,[],M).
rem_ws_acc([],A,A).
rem_ws_acc([H|T],A,L):- starts_with_return(H), rem_ws_acc(T,A,L).
rem_ws_acc([H|T],A,L):- rem_ws_acc(T,[H|A],L).
but I'm not overly happy with how they're working as I try to process the elements--it adds a level of complexity I'd rather do without.
I don't need to write the xml back out, so I don't care about the carriage returns.
Any help will be much appreciated!