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),
construct_singleton_avl_set((string(xmlLineNumber),string(LineNrAtom)),MetaAttributes),
l_convert_xml_attributes(Attributes,BAttributesList),
convert_to_avl(BAttributesList,BAttributes)
},
convert_xml_content_to_b(Content,NextId,Id2,OutId).
convert_xml_element(namespace( URL, NS, Element), ParentId,NextId,OutId) --> !, % what should we do with the namespace?
{(URL='', NS=[] -> true
; get_counter(xml2b_current_line,LineNr),
format('*** Ignoring XML namespace "~s" annotation on line ~w with URL: ~w~n',[NS,LineNr,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) --> !,
{get_counter(xml2b_current_line,LineNr),
format('Ignoring XML instructions annotation on line ~w: ~w : ~w~n',[LineNr,Name,Chars])}.
convert_xml_element(doctype(Tag, DoctypeId),_,Id,Id) --> !,
{get_counter(xml2b_current_line,LineNr),
format('Ignoring XML doctype annotation on line ~w: ~w : ~w~n',[LineNr,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) -->
{get_counter(xml2b_current_line,LineNr),
format('*** Unknown XML element on line ~w: ~w~n',[LineNr,El])}.