Expand my Community achievements bar.

SOLVED

XML-110018 Error while parsing XML string

Avatar

Level 2

Hi,
I'm trying to read a variable and I get this error "XML-110018 Error while parsing XML string" here is my code : 

 var query = xtk.queryDef.create(
      <queryDef schema="xtk:schema" operation="select" lineCount="1">      
        <select>       
          <node expr="data" alias="data"/>
        </select>
        <where>
          <condition expr={"@namespace='nms'"}/>
          <condition expr={"@name='recipient'"}/>
        </where>     
      </queryDef>);
    var queryResult = query.ExecuteQuery(); // START QUERy
logInfo("Data type :"+ typeof queryResult[0].data);

var xml = new DOMDocument.fromXMLString(queryResult[0].data.toXMLString());
var tag = xml.getElementsByTagName("attribute")[0];
1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @AnasSpir05,

 

Change your line to this:

 

var xml = DOMDocument.fromXMLString("<?xml version='1.0'?> " + queryResult.schema[0].toString());

This will populate your "tag" variable without error.

 

Thanks,

Ishan

View solution in original post

7 Replies

Avatar

Community Advisor

Hi @AnasSpir05 ,

 

Please check  the below part given in your code highlighted in yellow colour:

 

LakshmiPravallika_0-1686232055110.png

It should be having "@data "instead of "data" . Please cross check this and run it again.

 

Regards,

Pravallika.

 

 

 

Avatar

Level 2

hi @LakshmiPravallika ,

thank you for your reply but it still doesn't work and in the data schema it has the type memo with the tag element not attribute.

 

Avatar

Community Advisor

Hi @AnasSpir05 ,

 

Instead of trying to call the variables directly(replace last 3 lines with below), try using for each loop and print them as below:

 

for each (var row in queryResult)
{
logInfo("data printing "+row.data);

}

Avatar

Level 5

Hi,

 

Need more context but try this 

var query = xtk.queryDef.create(
    <queryDef schema="xtk:schema" operation="select" lineCount="1">      
      <select>       
        <node expr="data" alias="data"/>
      </select>
      <where>
        <condition expr="@namespace='nms'"/>
        <condition expr="@name='recipient'"/>
      </where>     
    </queryDef>
);

var queryResult = query.ExecuteQuery(); // START QUERY
logInfo("Data type :"+ typeof queryResult[0].data);

var xmlString = queryResult[0].data.toXMLString();

logInfo("XML String : " + xmlString);

var xml = new DOMDocument.fromXMLString(xmlString);
var tag = xml.getElementsByTagName("attribute")[0];

Hope it works.

 

Thanks

Madhan

 

 

Avatar

Correct answer by
Community Advisor

Hi @AnasSpir05,

 

Change your line to this:

 

var xml = DOMDocument.fromXMLString("<?xml version='1.0'?> " + queryResult.schema[0].toString());

This will populate your "tag" variable without error.

 

Thanks,

Ishan

Avatar

Level 2

@isahore has addressed a few issues in that reply.

  1. When executing your query, you will build a "schema" collection, rather than a "data" collection, which the original code assumes
  2. The XML declaration is not always necessary, but is best practice.
  3. The toXMLString is not necessary, but not problematic in this case. You can just use the toString function, because it will be constructed as an xml object anyway, because you're using the DOMDocument.fromXMLString function. Either approach works here, but I suspect there is less processing required just using toString rather than toXMLString.