XML value inside element

Hi everybody,
I’m struggling with Italian electronic invoice XML files and, as far as I’m not a huge fan of this kind of format, I guess I need a little help.
Browsing around Xojo manual I cannot find the solution for returning (in the e-invoice below) just the string “MY_SELLER” which is around the bottom of the code., between and .
It’s inside an element, not just an attribute and I don’t know where to start digging.
Can you please lend me a had?
Thanks everyone for the kind help.

<?xml version="1.0" encoding="UTF-8"?>
<p:FatturaElettronica versione="FPR12" xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:p="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ivaservizi.agenziaentrate.gov.it/docs/xsd/fatture/v1.2 fatturaordinaria_v1.2.xsd ">
  <FatturaElettronicaHeader>
<DatiTrasmissione></DatiTrasmissione>
<CedentePrestatore>
      <DatiAnagrafici>
        <IdFiscaleIVA>
          <IdPaese>IT</IdPaese>
          <IdCodice>blablabla</IdCodice>
        </IdFiscaleIVA>
        <CodiceFiscale>blablabla</CodiceFiscale>
        <Anagrafica>
          <Denominazione>MY_SELLER</Denominazione>
        </Anagrafica>
        <RegimeFiscale>blablabla</RegimeFiscale>
      </DatiAnagrafici>
</CedentePrestatore>
   

An XPath query should do it: https://documentation.xojo.com/api/text/xml/xmlnode.html#xmlnode-xql

Ideally, you would want a .stringvalue property to exist to handle this easily.
For whatever reason, Xojo treats the MY SELLER part as an unnamed child record
I suspect it is .firstchild and of type XMLTextNode

But I consider MY SELLER to ‘obviously’ be the value of the node, and it frustrates me now and then.

I’ve tried reading that document too but the example there written does not cover something it’s BETWEEN an element and its </> counterpart, it deals only with attributes.
Moreover, as I stated before I’m not so capable in XML world, so I really don’t know where to start from.

“MY SELLER” is a child of node and as jeff said, is a XMLTextNode

Ciao Riccardo,
the solution is easy:

dim myXmlNodeList as XmlNodeList
//xmlDoc is your xmlDocument
dim myDenominazione as string

myXmlNodeList=xmlDoc.DocumentElement.XQL("FatturaElettronicaHeader/CedentePrestatore/DatiAnagrafici/Anagrafica/Denominazione/text()", array("", ""))
if myXmlNodeList.length>0 then myDenominazione =myXmlNodeList.item(0).value

You can easy transform this in a module function extension as:

[code]Public Function getTextValue(extends x as XmlDocument, path as String, ns() as string = nil) as String
Dim myXmlNodeList As XmlNodeList

Dim myDenominazione As String

If ns=Nil Then
myXmlNodeList=x.DocumentElement.Xql(path, array("", “”))
Else
myXmlNodeList=x.DocumentElement.XQL(path, ns)
End If
If myXmlNodeList.length>0 Then return myXmlNodeList.item(0).value
End Function
[/code]
and call for any value you need as:

myDenominazione=xmlDoc.getTextValue("FatturaElettronicaHeader/CedentePrestatore/DatiAnagrafici/Anagrafica/Denominazione/text()")

Really, really thanks Antonio for the kind help!
I don’t understand yet how to properly use modules but the solution works really fine!
Grazie!

To create an extension method (IE add a method to an existing class without subclassing it) you just need to create a module (you can use whatever name, maybe a name that has some meaning for you, in this case it could be XMLextensions)

then add the relative function(s).

All the extension function has first parameter prefixed with extends.
The method must have a global scope.
then you can use it as original class method/function.

One note about the getTextValue function. It is coherent with getAttribute. IE reply with an empty string if the value is empty BUT ALSO if the node (or path) doesn’t exist. Keep it in mind when you use it.

PS: a better version is this one:

Public Function getTextValue(extends x as XmlDocument, path as String, ns() as string = nil) as String
  Dim myXmlNodeList As XmlNodeList
  
  Dim myDenominazione As String
  
  If ns=Nil Then
    myXmlNodeList=x.DocumentElement.Xql(path+"/text()", array("", ""))
  Else
    myXmlNodeList=x.DocumentElement.XQL(path+"/text()", ns)
  End If
  If myXmlNodeList.length>0 Then return myXmlNodeList.item(0).value
End Function

to be called with:

myDenominazione=xmlDoc.getTextValue("FatturaElettronicaHeader/CedentePrestatore/DatiAnagrafici/Anagrafica/Denominazione")

Ciao