cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X

createTextNode, entities, and json

TomLeoboldt
1-Newbie

createTextNode, entities, and json

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 2

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


Chris, this worked like a charm! Thank you!

Top Tags