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();
              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=""
  • 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 Jul 28 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 Jul 28 at 15:10

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).


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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.