EldoS | Feel safer!

Software components for data protection, secure storage and transfer

XPath problem

Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.
#29877
Posted: 06/23/2014 13:40:29
by Mauricio Ahumada (Basic support level)
Joined: 06/16/2014
Posts: 13

Hello, im having trouble getting a value from a specific node using the SecureBlackBox library.

When loading the following XML

Code
<?xml version="1.0" encoding="iso-8859-1"?>
<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:un:unece:uncefact:documentation:2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlns:sac="urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1" xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ext:UBLExtensions>
<ext:UBLExtension>
<ext:ExtensionContent>
<DatosAdicionales>
<Documento>
<Nombre>20101266819-03-BKR2-00000287</Nombre>
</Documento>
</DatosAdicionales>
</ext:ExtensionContent>
</ext:UBLExtension>
<ext:UBLExtension>
<ext:ExtensionContent>
<sac:AdditionalInformation>
<sac:AdditionalMonetaryTotal>
<cbc:ID>1001</cbc:ID>
<cbc:PayableAmount currencyID="PEN">165</cbc:PayableAmount>
</sac:AdditionalMonetaryTotal>
<sac:AdditionalMonetaryTotal>
<cbc:ID>1002</cbc:ID>
<cbc:PayableAmount currencyID="PEN">0</cbc:PayableAmount>
</sac:AdditionalMonetaryTotal>
<sac:AdditionalMonetaryTotal>
<cbc:ID>1003</cbc:ID>
<cbc:PayableAmount currencyID="PEN">0</cbc:PayableAmount>
</sac:AdditionalMonetaryTotal>
</sac:AdditionalInformation>
</ext:ExtensionContent>
</ext:UBLExtension>
<ext:UBLExtension>
<ext:ExtensionContent><ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#"><ds:SignedInfo><ds:CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315#WithComments"/><ds:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1"/><ds:Reference URI=""><ds:Transforms><ds:Transform Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature"/></ds:Transforms><ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"/><ds:DigestValue>jRNx5uoRrC2UcrSNyJjdZRTB8/o=</ds:DigestValue></ds:Reference></ds:SignedInfo><ds:SignatureValue>l0+StaNuMTnSqA1WRUwkeTPfcV51qiDCgNJWAjAs45UJdXH4Foij4vem1S1M6TyJTkq+Un4LeTBYqtz5DBUReIVvC8U1+JZeJ...DG6k=</ds:SignatureValue><ds:KeyInfo><ds:KeyValue><ds:RSAKeyValue><ds:Modulus>uuDsj+wOxKJuSP/rB/s9sydLWpQzjH3UIWeHlitmY/1ld7IbBncNNAKPOtDhM/kyZFURzxKJoSE+/0KzRLDuDkFjCHXyAdPVuOXL6PRWlAt/HnijjKPsICck8o+ckqJBvgy2HiLVgXmWBzkZSkPX0hcopjoP5EaY4J5S05q6GIs=</ds:Modulus><ds:Exponent>AQAB</ds:Exponent></ds:RSAKeyValue></ds:KeyValue><ds:X509Data><ds:X509IssuerSerial><ds:X509IssuerName>CN=SUNAT, DC=SUNAT</ds:X509IssuerName><ds:X509SerialNumber>417359200896994877898782</ds:X509SerialNumber></ds:X509IssuerSerial><ds:X509SubjectName>E=jnunezv@sagafalabella.com.pe, CN=Jose Nuñez, OU=20100128056, O=SAGA, L=LIMA, ST=LIMA, C=PE</ds:X509SubjectName><ds:X509Certificate>MIIERzCCAy+gAwI...rg7I/sDsSibkj/6wf7...bjly+j0VpQLfx54o4yj7CAnJPKPnJKiQb4Mth4i1YF5lgc5GUpD19IXKKY6D+RGmO...s0xx+55MZ3Uc7I60wM/lqagsXGt7B6KMcug9AudbcLdd3SGKfMU5gS1B8eT/ZY5WZQUdLm21ykKKvWiM+exH/GqZJ96RwVMU6OMGXQxRl0X4CkzA51Pu+2NnbMQ5DpDvVd4bKVi4OxplyV4c3fQEmz3ZNCcR2neDAskKKDR4FTp6cjjOjzK+Pv6ItXhdGwWwNleyOd0ZCelFMRzBegfGejaE+SOUR1u8WLLlfQL89YRLE+oomFBlnwYy440PI47JMCWpW6vH9yG1dG3HmtIAfixG//KJQDZmCTvXfIU4S+22/5QRXZgw09loWsH4FwH35mg==</ds:X509Certificate></ds:X509Data></ds:KeyInfo></ds:Signature>
</ext:ExtensionContent>
</ext:UBLExtension>
</ext:UBLExtensions>
<cbc:UBLVersionID>2.0</cbc:UBLVersionID>
<cbc:CustomizationID>1.0</cbc:CustomizationID>...


And using .NET C# with the following code:

Code
////////////////////////////////////////////
            XmlDocument doc2 = new XmlDocument();
            doc2.Load(new XmlTextReader(@"C:\DBNeT\xmlsec\20101266819-03-BKR2-00000287.FIRM.xml"));
            //Instantiate an XmlNamespaceManager object.
            System.Xml.XmlNamespaceManager XmlNSMap = new System.Xml.XmlNamespaceManager(doc2.NameTable);

            XmlNSMap.AddNamespace("cac", "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2");
            XmlNSMap.AddNamespace("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
            XmlNSMap.AddNamespace("ccts", "urn:un:unece:uncefact:documentation:2");
            XmlNSMap.AddNamespace("ext", "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2");
            XmlNSMap.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");
            XmlNSMap.AddNamespace("qdt", "urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2");
            XmlNSMap.AddNamespace("sac", "urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1");
            XmlNSMap.AddNamespace("udt", "urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2");
            XmlNSMap.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");

doc2.DocumentElement.SelectNodes("ext:UBLExtensions/ext:UBLExtension[3]/ext:ExtensionContent/ds:Signature/ds:SignedInfo/ds:Reference/ds:DigestValue",XmlNSMap)[0].InnerText;


I get the correct value: "jRNx5uoRrC2UcrSNyJjdZRTB8/o="

However I dont seem able to do the same using the blackbox libraries, for instance this code:

Code
TElXMLDOMDocument XMLDocument = new TElXMLDOMDocument();
                XMLDocument.LoadFromFile(FileName); //HERE IS THE ERROR
                TElXMLNamespaceMap XmlNSMap = new TElXMLNamespaceMap();
                XmlNSMap.AddNamespace("cac", "urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2");
                XmlNSMap.AddNamespace("cbc", "urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2");
                XmlNSMap.AddNamespace("ccts", "urn:un:unece:uncefact:documentation:2");
                XmlNSMap.AddNamespace("ext", "urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2");
                XmlNSMap.AddNamespace("ds", "http://www.w3.org/2000/09/xmldsig#");
                XmlNSMap.AddNamespace("qdt", "urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2");
                XmlNSMap.AddNamespace("sac", "urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1");
                XmlNSMap.AddNamespace("udt", "urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2");
                XmlNSMap.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
XMLDocument.DocumentElement.SelectNodes("ext:UBLExtensions/ext:UBLExtension",XmlNSMap);


The last line will select three ext:UBLExtension nodes (thats correct), however i cant use the "index tag" to select the third node (which is the one im looking for) i want to do exactly the same as in .NET

doc2.DocumentElement.SelectNodes("ext:UBLExtensions/ext:UBLExtension[3]/ext:ExtensionContent/ds:Signature/ds:SignedInfo/ds:Reference/ds:DigestValue",XmlNSMap)[0].InnerText;

What I'm doing wrong?
#29879
Posted: 06/23/2014 17:20:26
by Dmytro Bogatskyy (EldoS Corp.)

Thank you for contacting us.

What version are you testing?
I have tested your code with the latest snapshot build and it selects a correct node(s).
If it pre-release build 253, it might have this issue. Then it will be fixed in the next build.

P.S. If you have loaded a signature into TElXMLVerifier object, then you can access a digest value using Verifier.References.get_References(0).DigestValue property.
#29895
Posted: 06/24/2014 08:13:56
by Mauricio Ahumada (Basic support level)
Joined: 06/16/2014
Posts: 13

Thanks for the reply. Im using a custom build that was sent to me by Mr. Mayesvky on this thread https://www.eldos.com/helpdesk/ticket_edit.php?SHOWALL_1=1&ID=25502#nav_start In any case, the assemblies shows 12.0.255.0 as the version. Im developing on a windows mobile device, especifically the Intermec CN50 (windows 6.1).
#29917
Posted: 06/24/2014 13:08:35
by Dmytro Bogatskyy (EldoS Corp.)

Thank you for the info. I will recheck it. It is possible that a fix wasn't included in this custom build.
#29935
Posted: 06/25/2014 14:05:58
by Mauricio Ahumada (Basic support level)
Joined: 06/16/2014
Posts: 13

And I have another problem that may or may not be related. Having the following XML

Code
<?xml version="1.0" encoding="iso-8859-1"?>
<CreditNote xmlns="urn:oasis:names:specification:ubl:schema:xsd:CreditNote-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:un:unece:uncefact:documentation:2" xmlns:ext="urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2" xmlns:ds="http://www.w3.org/2000/09/xmldsig#" xmlns:qdt="urn:oasis:names:specification:ubl:schema:xsd:QualifiedDatatypes-2" xmlns:sac="urn:sunat:names:specification:ubl:peru:schema:xsd:SunatAggregateComponents-1" xmlns:udt="urn:un:unece:uncefact:data:specification:UnqualifiedDataTypesSchemaModule:2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<cac:AccountingSupplierParty>
<cbc:CustomerAssignedAccountID>20101266819</cbc:CustomerAssignedAccountID>
<cbc:AdditionalAccountID>6</cbc:AdditionalAccountID>
<cac:Party>
<cac:PartyName>
<cbc:Name><![CDATA[TOTTUS HIPERMERCADO]]></cbc:Name>
</cac:PartyName>
<cac:PostalAddress>
<cbc:ID>150113</cbc:ID>
<cbc:StreetName>AV.GIUSEPPE GARIBALDI N°396</cbc:StreetName>
<cac:Country>
<cbc:IdentificationCode>PE</cbc:IdentificationCode>
</cac:Country>
</cac:PostalAddress>
<cac:PartyLegalEntity>
<cbc:RegistrationName><![CDATA[CAMARA DE COMERCIO DE LIMA]]></cbc:RegistrationName>
</cac:PartyLegalEntity>
</cac:Party>
</cac:AccountingSupplierParty></CreditNote>


I need to get the vale of the line:

<cbc:CustomerAssignedAccountID>20101266819</cbc:CustomerAssignedAccountID>

I got the node...

Code
TElXMLDOMNode ValueINeed = XMLDocument.FindNode("cac:AccountingSupplierParty", true).FindNode("cbc:CustomerAssignedAccountID");


and then tried using the innerXml or innerText to get the value, however I'm unable to do so. I also tried the NodeValue property but all i got was an empty string.

I cant find any useful documentation on the class reference page

https://www.eldos.com/documentation/sbb/documentation/ref_cl_xmldomnode.html

Any ideas?
#29937
Posted: 06/25/2014 14:50:52
by Dmytro Bogatskyy (EldoS Corp.)

Quote
and then tried using the innerXml or innerText to get the value, however I'm unable to do so.

Did you try to cast to TElXMLDOMElement class as following:
Code
if (ValueINeed is TElXMLDOMElement)
((TElXMLDOMElement)ValueINeed).InnerXML()
or
((TElXMLDOMElement)ValueINeed).TextContent

See: https://www.eldos.com/documentation/sb...ntent.html
#29938
Posted: 06/25/2014 16:45:41
by Mauricio Ahumada (Basic support level)
Joined: 06/16/2014
Posts: 13

No, I hadn't but it worked perfectly. Thanks!
Also by EldoS: Rethync
The cross-platform framework that simplifies synchronizing data between mobile and desktop applications and servers and cloud storages

Reply

Statistics

Topic viewed 1667 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!