I’m using libxml2 in a C program to do some stuff within XML documents.
Now… if I look to the following XPath I have an empty result.
/scheda_conservatore[1]/patrimonio_archivistico[1]/lower_list[@type='risorsa_informativa']/risorsa_informativa_nested[@id='037006-001-2012-ri002']
but… If I look for the following XPAth I have a non empty result containing elements that should have been matched even from the first one.
/scheda_conservatore[1]/patrimonio_archivistico[1]/lower_list/risorsa_informativa_nested[@id='037006-001-2012-ri002']
Now… if I check, step by step, my XPath I have…
/scheda_conservatore[1] -> Non empty node set /scheda_conservatore[1]/patrimonio_archivistico[1] -> Non empty node set /scheda_conservatore[1]/patrimonio_archivistico[1]/lower_list[@type='risorsa_informativa'] -> Empty Node set.
As I told before, the XML document DO contain a valid path but this is not matched by this request.
More: If I ask jEdit or other editors having XPath support to solve XPath expression for me, the result is a non empty node set.
I’m going mad. I watched the XPath expression thousands of times and there must be somethig very wrong at least as very hidden to my eyes even if it will surelly be brilliant to somebody else.
More…
The following, just asking for the ‘type’ attribute without looking at it’s value, give a valid result. But the value is also correct.
/scheda_conservatore[1]/patrimonio_archivistico[1]/lower_list[@type]/risorsa_informativa_nested[@id=’037006-001-2012-ri002′]
Here’s a “director’s cut” of the larger XML document
<?xml version="1.0" encoding="iso-8859-1"?>
<scheda_conservatore anno_rilevazione="2012" stato="non-storicizzata">
<!-- scheda 2012 per Bologna -->
<patrimonio_archivistico>
<lower_list type="complesso_archivistico">
<complesso_archivistico_nested id="037006-001-2012-ca001" inventariazione="n">
<lower_list type="altro_luogo_collocazione">
<altro_luogo_collocazione_nested id="037006-001-2012-alc001">
<!-- altro luogo 1 per bologna 2012 -->
<upper_list type="complesso_archivistico">
<upper ref="ca002"/>
<upper ref="ca003"/>
</upper_list>
<ubicazione>sotterraneo da botola segreta</ubicazione>
<bridge_list type="sede">
<bridge ref="s001"/>
</bridge_list>
</altro_luogo_collocazione_nested>
</lower_list>
<!-- complesso 1 per bologna 2012 -->
<identificazione>
<denominazione>Archivi dei Comprensori della provincia di Bologna</denominazione>
<lista_altre_denominazioni>
<!-- Modificato -->
<altra_denominazione>Archivi dei Comprensori bolognesi</altra_denominazione>
<altra_denominazione>Archivi dei Comprensori felsinei</altra_denominazione>
</lista_altre_denominazioni>
<livello>Complesso di fondi, Superfondo</livello>
</identificazione>
<dati_giuridici>
<tipologia>Pubblico</tipologia>
<notificato_dichiarato presente="y">
<data>20100304T000000</data>
</notificato_dichiarato>
</dati_giuridici>
<lower_list type="titolare">
<titolare_nested id="037006-001-2012-t001">
<!-- titolare 1 per bologna 2012 -->
<upper_list type="complesso_archivistico">
<upper ref="ca001"/>
<upper ref="ca002"/>
</upper_list>
</titolare_nested>
</lower_list>
</complesso_archivistico_nested>
</lower_list>
<lower_list type="risorsa_informativa">
<risorsa_informativa_nested id="037006-001-2012-ri001">
<bridge_list type="complesso_archivistico">
<bridge ref="ca001"/>
<bridge ref="ca002"/>
</bridge_list>
<!-- risorsa 1 per bologna 2012 -->
<descrizione>
<autore>CSR - Centro studi e ricerche</autore>
<titolo>Atti degli uffici: inventario-mappa topografica del...</titolo>
<anno indicativo="y">1986</anno>
<qualifica>
<opz pubbl="y">Strumenti di ricerca archivistici</opz>
</qualifica>
<scelta_multipla nome="standard">
<opz valore="AACR2"/>
<opz valore="Altro">EAD</opz>
</scelta_multipla>
<descr_estrinseca>Dattiloscritto (relativo a: documentazione post 1945 conservata in Viale Martiri della Libert&#x2026;)</descr_estrinseca>
</descrizione>
<lista_pubblicazioni>
<pubblicazione>
<edita presente="y">stampa</edita>
<edita_stampa>
<curatore/>
<edito_in/>
<luogo/>
<data/>
<pagine/>
<sbn/>
<note/>
</edita_stampa>
<url/>
<ultima_consultazione>20120611T165400</ultima_consultazione>
<nota>Nessuna nota</nota>
</pubblicazione>
<pubblicazione>
<edita presente="y">web</edita>
<edita_stampa/>
<url>www.risorsainformativa.gov</url>
<ultima_consultazione/>
<nota>Nessuna nota web</nota>
</pubblicazione>
</lista_pubblicazioni>
<informatizzazione presente="y">
<scelta_multipla nome="applicativi_utilizzati">
<!-- MODIFICATO!! -->
<opz valore="Access (database)"/>
<opz valore="Altro">eXtraWay</opz>
</scelta_multipla>
<partecipazione_sistemi_informativi presente="y">
<descrizione>x.dams</descrizione>
</partecipazione_sistemi_informativi>
</informatizzazione>
</risorsa_informativa_nested>
</lower_list>
<lower_list type="intervento">
<intervento_nested autor_sovraintendenza="y" id="037006-001-2012-i001" in_corso="y">
<!-- intervento 1 per bologna 2012 -->
<descrizione>Restauro archivi dei comprensori della provincia di Bologna</descrizione>
<scelta_multipla nome="tipologia">
<opz valore="Riordino"/>
<opz valore="Altro">Pulizia</opz>
</scelta_multipla>
<avvio>20111101T000000</avvio>
<conclusione_prevista>20120701T000000</conclusione_prevista>
<conclusione_effettiva/>
<autore/>
<promotore/>
<scelta_multipla nome="standard_descrittivi">
<opz valore="ISAD"/>
<opz valore="Altro">Descrizione altro standard descrittivo</opz>
</scelta_multipla>
<informatizzazione presente="y">
<scelta_multipla nome="applicativo_utilizzato">
<opz valore="Access (database)"/>
<opz valore="Altro">eXtraWay</opz>
</scelta_multipla>
<partecipazione_sistemi_informativi presente="y">
<descrizione>x.dams</descrizione>
</partecipazione_sistemi_informativi>
</informatizzazione>
<bridge_list type="complesso_archivistico">
<bridge ref="ca001"/>
</bridge_list>
</intervento_nested>
</lower_list>
<note/>
</patrimonio_archivistico>
<note/>
<?xw-meta Dbms="ExtraWay" DbmsVer="24.3.1" OrgNam="3D Informatica" OrgVer="1.0" Classif="1.0" ManGest="3.1" ManTec="0.0.4" DocType="" InsUser="admin" InsTime="20120910175739" ModUser="rtirabassi" ModTime="20120925145347"?>
<?xw-crc key32=e324f581-406521b5?>
</scheda_conservatore>
Ok, now the problem is assuming another aspect. Probably I have to “close” this and pass to another quiestion.
XPath, on the originale (wider) XML document, is correct and now I see where the problem is but have no idea about how to solve it.
- If I execute just once the XPath expression onto the XML document, I HAVE THE EXPECTED RESULT;
- If I execute a pretty large sequence of XPath onto the same XML document, complex XPaths (containing condition concerning attribute values) fails (those ones and only those);
So I took a look on how we implemented the XPath evaluation and find that the XPathContext saw never freed. So I changed the code in order to free the context after each XPath evaluation and create a new one everytime but… nothing changes.
Any Idea?
XPath works correctly. You are looking for
@id='037006-001-2012-ri002and the attribute value is037006-001-2012-ri001. After changing xml tori002it matches, libxml returns the correct nodesetval.In case it does not really resolve the problem: maybe
idattribute is treated in a special way? Try changing it toidx. See Java XML DOM: how are id Attributes special?