1

I've getting a problem when trying to parse an XML. The logs says:

System.XmlException: Failed to parse XML due to: markup not allowed inside attribute value - illegal < (position: START_TAG seen ...la.ccbdw.dbo.ft_certificas TxtCertificado="AGENCIA : BOGOTA (2).\n<... @3:2)

The code that thows that exception is the following:

    strReturn = strReturn.unescapeHtml4().unescapeXml();
    
    objDocument = null;
    objDocument = new DOM.Document();
    
    
    try{
              strReturn = strReturn.replace('&', '&amp;');
              objDocument.load(strReturn); //The problem occurs here
    
    
    
              bodyNode = objDocument.getRootElement();
    
    
              DOM.XmlNode datosBasicosNode = bodyNode.getChildElement('DatosBasicos', null);
              //------------
    }catch(Exception objException){
              System.debug(' ERROR ===> '+objException.getMessage());
    }

strReturn is the XML that I try to parse to get the 'DatosBasicos'. I'm try to understand what's going on.

What should I do to fix the problem?

The squeleton of the XML

<?xml version="1.0" encoding="ISO-8859-1"?>
<DatosBasicos ciudad="" esConfecamaras=""><DatosBasicos>
<IdClase> </IdClase>
<NumId> </NumId>
<NombreCliente> </NombreCliente>
<OrganizacionJuridica> </OrganizacionJuridica>
<CategoriaEmpresa> </CategoriaEmpresa>
<NroMatricula> </NroMatricula> <FecMatricula>
<paralela.ccbdw.dbo.ft_certificas TxtCertificado=""
<paralela.ccbdw.dbo.ft_certificas TxtCertificado=""
<paralela.ccbdw.dbo.ft_certificas TxtCertificado=""
<paralela.ccbdw.dbo.ft_certificas TxtCertificado=""
</TxtCertificado></DatosConstitucion><DatosError><CodRetorno>0</CodRetorno></DatosError></DatosBasicos>
2
  • 2
    The error here is describing a problem with the XML rather than the code you're using to process it. Please edit your question to provide the XML you're trying to parse.
    – Derek F
    Commented Jul 28, 2020 at 14:33
  • There's a hint from the error that the attribute TxtCertificado has a value that includes "<". This should have previously been encoded to "&lt;" instead.
    – Phil W
    Commented Jul 28, 2020 at 15:10

1 Answer 1

2

The XML is malformed. These lines are suspect:

<DatosBasicos ciudad="" esConfecamaras=""><DatosBasicos>

Is this really supposed to be a DatosBasicos with a nested DatosBasicos?

<NroMatricula> </NroMatricula> <FecMatricula>

This includes an open tag for FecMatricula, but there's no closing tag later in the document.

<paralela.ccbdw.dbo.ft_certificas TxtCertificado=""
<paralela.ccbdw.dbo.ft_certificas TxtCertificado=""
<paralela.ccbdw.dbo.ft_certificas TxtCertificado=""
<paralela.ccbdw.dbo.ft_certificas TxtCertificado=""

The self-close tag markup is missing (the "/>" is missing at the end of each line).

</TxtCertificado>...

There's no open tag to match this closing tag. Other open and close tags on this line are also unbalanced.

Whatever is generating this XML is doing a really bad job.

3
  • To be pedantic, self-closing means <tag />, otherwise it's just a normal closing tag (</tag>).
    – sfdcfox
    Commented Jul 28, 2020 at 21:22
  • @sfdcfox but that is what I said... missing "/>"...
    – Phil W
    Commented Jul 29, 2020 at 6:34
  • Oh. Looks like I misread/confused myself. Carry on. 😊
    – sfdcfox
    Commented Jul 29, 2020 at 6:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .