Extract the contents of a node from an XML file

Dear Friends
XOJO

Grateful for the attention of the present and that this year 2020 that has just begun will fulfill all its goals and that will prosper greatly.

I need your comments, to resolve the following:

I have an XML file, from which I need to browse its content, to extract the content of the NODE whose name is , and the value it contains is as follows:
/ NiiuOhBRZcavHVK4nhHsUHN0SNinZ + Z2BWyrvjAh8M =

The content of the XML file is as follows:


<?xml version="1.0" encoding="ISO-8859-1" standalone="no"?><?xml-stylesheet type="text/xsl" href="boleta2.1.xsl"?><Invoice xmlns="urn:oasis:names:specification:ubl:schema:xsd:Invoice-2" xmlns:cac="urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2" xmlns:cbc="urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2" xmlns:ccts="urn:oasis:names:specification:ubl:schema:xsd:CoreComponentParameters-2" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlns:sac="urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1" xmlns:stat="urn:oasis:names:specification:ubl:schema:xsd:DocumentStatusCode-1.0" xmlns:udt="urn:un:unece:uncefact:data:draft:UnqualifiedDataTypesSchemaModule:2">
	<ext:UBLExtensions>	 
	  <ext:UBLExtension>	
		<ext:ExtensionContent>
			<sac:AdditionalInformation>
			</sac:AdditionalInformation>
      </ext:ExtensionContent>
    </ext:UBLExtension>
  <ext:UBLExtension><ext:ExtensionContent><Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" /><SignatureMethod Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" /><Reference URI=""><Transforms><Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" /><Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /></Transforms><DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" /><DigestValue>/NiiuOhBRZcavHVK4nhHsUHN0SNinZ+Z2BWyrvjAh8M=</DigestValue></Reference></SignedInfo><SignatureValue>B9MzP1ENOLfwvqtghOQhD6dgsp7+B0hPF/WOBH1T2wUCsTsLvNy+L4/sMYZT58s60neqJHQxWTxI9uT/AbjZ5AXVqr34xwmOVbLNwjWTIY4bCrYn79n3YjocteeOtxXWDSe7Tf2V2unVjlS13aSkZU/FLlTLlH7BMnnU4R9RZvsXVB59uusXHFmsVr54G+Vp09Z3NHjbCzvW/9cKYj6ERNYHEckKIqfhs04nmqAG0AUaeY7ibk9RfvqBY93vA/MOSp+0S8zJjdxY0rFh/xUEEQMT7RgTSiQttxFS9I5zIjtZQO9dWscCVqdDzlXgh/bF8Jpia/8PBghwGhiFo2JlBg==</SignatureValue><KeyInfo><X509Data><X509SubjectName>CN=AC CAMERFIRMA PER CERTIFICADOS - 2016, O=CAMERFIRMA PER S.A.C., OID.2.5.4.97=NTRPE-20566302447, SERIALNUMBER=20566302447, OU=AC CAMERFIRMA PER CERTIFICADOS - 2016, OU=see current address at www.camerfirma.com.pe/address, L=LIMA, S=LIMA, C=PE</X509SubjectName><X509Certificate>MIIKrTCCCJWgAwIBAgIJPS+cbfuqHKg2MA0GCSqGSIb3DQEBCwUAMIIBIjELMAkGA1UEBhMCUEUxDTALBgNVBAgMBExJTUExDTALBgNVBAcMBExJTUExPTA7BgNVBAsMNHNlZSBjdXJyZW50IGFkZHJlc3MgYXQgd3d3LmNhbWVyZmlybWEuY29tLnBlL2FkZHJlc3MxMDAuBgNVBAsMJ0FDIENBTUVSRklSTUEgUEVSw5ogQ0VSVElGSUNBRE9TIC0gMjAxNjEUMBIGA1UEBRMLMjA1NjYzMDI0NDcxGjAYBgNVBGEMEU5UUlBFLTIwNTY2MzAyNDQ3MSAwHgYDVQQKDBdDQU1FUkZJUk1BIFBFUsOaIFMuQS5DLjEwMC4GA1UEAww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56js4SFjsDp6YHtboO/X6g+fI5yjJZTgPqIaQSoM6DxMvLGIpqPeyKaD7HuoH1eA==</X509Certificate></X509Data></KeyInfo></Signature></ext:ExtensionContent></ext:UBLExtension></ext:UBLExtensions>
	

.....
		
</Invoice>

The xojo code is as follows:


Dim root As XmlNode
root = xml.DocumentElement

For i As integer = 0 To root.ChildCount-1
  For j As integer =0 To root.Child(i).ChildCount-1
    Dim node As XmlNode=root.child(i).Child(j)
   
    SELECT CASE node.Name
    
    CASE "<DigestValue>"
    MsgBox " "+node.Name.Uppercase+" valor i "+str(i)+ " valor j "+str(j)+ " "+node.Child(0).Value
    
    END SELECT
  Next 
Next

I tried but failed to locate the NODE

Your answers will be greatly appreciated.

Cordially,

Raul Juarez Pulache

You can use the XMLReader class. Add the StartElement, EndElement and Characters Event, define a Boolean property “IsNode” to this class and there the following lines of code to the StartElement Event:

Select Case name Case "DigestValue" // Get each DigestValue node IsNode = True End Select
Add the following lines to the EndElement Event:

Select Case name Case "DigestValue" // Get each DigestValue node IsNode = False End Select
Add the following lines to the Characters Event:

If IsNode Then MsgBox(S)

Thank you so much
Martin Trippensee

I am trying what I recommend, but I get an error when executing the following line of code.

reader.Parse (f)


Dim reader As New XmlReader
Dim f as FolderItem  
Dim ruta As String = "D:\\Sistema Ventas\\XML\\BOLETAEB01-27410167715562.XML"
f=GetFolderItem(ruta)
IF f <> nil then
  reader.Parse(f)
Else
  MsgBox "El archivo es nulo"
End If

Any comments, to solve the problem.

Very thankful

Raul Juarez Pulache

You need to create a Class, set their Super to XmlReader and then you can insert the pre-defined events.

[quote=470149:@Raul Juarez Pulache]

Dim reader As New XmlReader

If you declare the class in code won’t work.

Thank you so much
Martin Trippensee

the TestXmlReader class was created with super XMLReader, and with the StartElement event.

But it seems to me that in f is the error


Dim reader As New TestXmlReader
Dim f as FolderItem  
Dim ruta As String = "D:\\Sistema Ventas\\XML\\BOLETAEB01-27410167715562.XML"
f=GetFolderItem(ruta)
IF f <> nil then
  reader.Parse(f)
Else
  MsgBox "El archivo es nulo"
End If

The file path is correct because it loads correctly, with the following code:

Dim xml As new XmlDocument
Dim f as FolderItem  
Dim ruta As String = "D:\\Sistema Ventas\\XML\\BOLETAEB01-27410167715562.XML"
f=GetFolderItem(ruta)
IF f <> nil then
  Try
    xml.LoadXml(f)
  Catch e As XmlException
    MsgBox("XML error: " + e.Message)
  End Try
Else
  MsgBox "El archivo es nulo"
End If

Any ideas?

Raul Juarez Pulache

Var f As FolderItem = FolderItem.ShowOpenFileDialog("text") // as defined in File Type Sets Editor If f <> Nil Then If f.Exists Then // Be aware that TextInputStream.Open could raise an exception Var t As TextInputStream Try t = TextInputStream.Open(f) t.Encoding = Encodings.UTF8 reader.Parse(t.ReadAll) Catch e As IOException MessageBox("Error accessing file.") End Try t.Close End If End If

You might also try using XQL

Right.
With XQL you can do:

Var map() As String=Array("ext", "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2", "ds", "http://www.w3.org/2000/09/xmldsig#") Var xq As XmlNodeList=xml.DocumentElement.Xql("ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/ds:Signature/ds:SignedInfo/ds:Reference/ds:DigestValue/text()", map) If xq.Length>0 Then Dim theValue As String=xq.Item(0).Value //theValue is what you are looking for end if

Infinite Thank you
Antonio Rinaldi
Jim mckay
Martin Trippensee

With your great help I was able to solve the problem

Many Blessings to you and your family

Dim xml As new XmlDocument
Dim f as FolderItem  
Dim ruta As String = "D:\\Sistema Ventas\\XML\\BOLETAEB01-27410167715562.XML"
f=GetFolderItem(ruta)
IF f <> nil then
  
  xml.LoadXml(f)
  
  Dim map() As String=Array("ext", "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2", "ds", "http://www.w3.org/2000/09/xmldsig#")
  Dim xq As XmlNodeList=xml.DocumentElement.Xql("ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/ds:Signature/ds:SignedInfo/ds:Reference/ds:DigestValue/text()", map)
  If xq.Length>0 Then
    Dim theValue As String=xq.Item(0).Value
    MsgBox "  "+theValue
  End if
  
  
Else
  MsgBox "El archivo es nulo"
End If

Self.cmdSalir.SetFocus

Cordially,

Raul Juarez Pulache