convert_xml_element(Element, ParentId,NextId,OutId) -->
% {get_counter(xml2b_current_line,CurNr),nl,print(el(CurNr,Element)),nl},
{xml_element(Element,Tag,Attributes,Content,LineNr)},
!,
[(int(NextId),
rec([ % note: fields have to be in order
field(attributes,BAttributes), % partial function of Attributes
field(element,string(Tag)),
field(meta,MetaAttributes), % such as xmlLineNumber
field(pId,int(ParentId)), % id of the parent XML record
field(recId,int(NextId)) % id of the XML element/record
])
)],
{Id2 is NextId+1,
number_codes(LineNr,LCC), atom_codes(LineNrAtom,LCC),
convert_to_avl([(string(xmlLineNumber),string(LineNrAtom))],MetaAttributes),
maplist(convert_xml_attributes,Attributes,BAttributesList),
convert_to_avl(BAttributesList,BAttributes)
},
convert_xml_content_to_b(Content,NextId,Id2,OutId).
convert_xml_element(namespace( URL, _, Element), ParentId,NextId,OutId) --> % what should we do with the name space ?
{format('*** Ignoring XML namespace annotation: ~w~n',[URL])},
convert_xml_element(Element, ParentId,NextId,OutId).
convert_xml_element(pcdata(_Codes),_,Id,Id) --> !. % should only happen when Codes consists solely of newlines
convert_xml_element(comment(Codes),_,Id,Id) --> !,{count_newlines(Codes)}.
convert_xml_element(instructions(Name, Chars),_,Id,Id) --> !,
{format('Ignoring XML instructions annotation: ~w : ~w~n',[Name,Chars])}.
convert_xml_element(doctype(Tag, DoctypeId),_,Id,Id) --> !,
{format('Ignoring XML doctype annotation: ~w : ~w~n',[Tag,DoctypeId])}.
convert_xml_element(cdata(Codes),ParentId,Id,OutId) --> !,
% TO DO: tab expansion? see http://binding-time.co.uk/wiki/index.php/Parsing_XML_with_Prolog
convert_xml_element(pcdata(Codes),ParentId,Id,OutId).
convert_xml_element(El,_,Id,Id) -->
{format('*** Unknown XML element: ~w~n',[El])}.