Skip to main content
1-Visitor
February 11, 2013
Question

createTextNode, entities, and json

  • February 11, 2013
  • 2 replies
  • 980 views

We have some data that is being exposed via a JSON web service that is being consumed in a custom XUI app. The content provided in the JSON data already has a variety of entity references in it (ex: &). When we pass this data to the createTextNode(...) method of the Document class, it translates the "&" character in the & entity to a "&", resulting in the value & being stored in the SGML document. Clearly, we could modify the JSON service to no longer output entity references, but is there another way to skin this cat? Is there a way to cause the createTextNode(...) Document class method not translate characters to entities as described above?


Alternative suggestions are welcome.



Regards,


Tom

    2 replies

    1-Visitor
    February 12, 2013
    Tom,



    There's an ACL function for that: entity_expand(str, 1, doc), where 'str' is
    the string with the entities, '1' means "expand character entities" (2 is
    text entities, 3 is both), and doc is the ACL ID of the document to use to
    look up the entity references. So assuming you're in Java:



    String docId = ((ADocument) doc).getAclId() + ";

    String fixedStr = Acl.func("entity_expand", str, "1", docId);

    Text textNode = doc.createTextNode(fixedStr);



    Another option would be to use the AOM ARange interface to insert the
    string.



    Range r = ((DocumentRange) doc).createRange();

    r.selectNodeContents(element);

    ((ARange) r).insertParsedString(str);

    r.detach(); // Dispose of the range's resources. Or reuse and detach when
    you're done.



    Chris


    1-Visitor
    February 21, 2013

    Chris, this worked like a charm! Thank you!