Google App Script - XML Parse - Can not get elements from 4th Child level

43 Views Asked by At
I Have this HTML, from google drive.
    
    <rDE xmlns="http://ekuatia.set.gov.py/sifen/xsd"
xmlns:ns2="http://www.w3.org/2000/09/xmldsig#" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://ekuatia.set.gov.py/sifen/xsd siRecep> 
DE_v150.xsd">   
            <DE Id="123456789">>    
                 <gDtipDE>> 
                    <gCamCond>
                       <iCondOpe>2</iCondOpe>
                       <gPagCred>
                          <iCondCred>2</iCondCred>
                          <dDCondCred>Cuota</dDCondCred>

My code (generic)

function getDataFromXML(fileId,Attribute,Child0,Child1,Child2,...,Childn)
  let data = DriveApp.getFileById(fileId).getBlob().getDataAsString();
      
  let doc = XmlService.parse(data);
    
  let root = doc.getRootElement(); 
    
  let namespace = XmlService.getNamespace('http://ekuatia.set.gov.py/sifen/xsd'); 
    
  var foods = root.getChild(Child0,namespace).getChild(Child1,namespace).getChild(Child2,namespace).getChildText(Attribute,namespace);

/// Child 0 its only 'DE', if I change, it's don´t work (I improve a lot to know).

My problem is that => it works up to node number 3 (Child0..1..2). That is, from the item 'gPagCred', I can't include getChild(Child3, namespace).getChildText(Attribute, namespace), because it returns "null". Can someone help-me?

I want have a form to access the data from deep nodes. It works until node 3 using root.getChild(0).getChild(1).getChild(2).getChildText(Attibute), if I include getChild(3) to access more deep nodes, it return "null" always.

I solve it. At really it works but I not configure if else estructure correctly (it don´t appear here). So, it works.

0

There are 0 best solutions below