Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

java xml parsing

  • 08-08-2009 9:03pm
    #1
    Registered Users, Registered Users 2 Posts: 134 ✭✭


    i'm trying to create an xml file using java but am having a problem with escape character. This is the code below:

    //add rule ref
    Element ruleref = document.createElement("ruleref");
    ruleref.setAttribute("uri", "#_"+MYDATA);
    PublicItem.appendChild(ruleref);

    //add tag
    Element tag = document.createElement("tag");
    PublicItem.appendChild(tag);
    //delegate the tag "MYDATA" value from the private rule
    String tagVal = "<![CDATA[MYDATA = "+ "\"_"+varData+".MYDATA\"; "+
    "dm_confirmation_mode=\"never\"; "+
    "crResultType=\"rSlot\"; "+
    "dm_root=\""+ MYDATA+ "\"" +
    "]]>";

    The problem is that when the document is created the '<' and '>' characters that exists within the the <tag> element are encoded as < and > and this results in the grammar not being valid.

    see output below for the current output:
    <tag><![CDATA[ MYDATA = "_111111.MYDATA"; dm_confirmation_mode="never"; rSlot="Speech"; dm_root="MYDATA"]]></tag>

    once the document is created i can then import the doc as an input stream and do a string replace to change the characters but this is not very elegant and has a significant overhead as some of the files are quite large.

    is there any way i can ensure these characters are not encoded when i first create the document? I am already using the Transformer class before I write to the output file first.


Comments

  • Registered Users, Registered Users 2 Posts: 1,916 ✭✭✭ronivek


    Try the following;
    ...
    CDATASection cDataSection = document.createCDATASection(myData);
    tag.appendChild(cDataNode);
    ...
    

    I'm not 100% sure if that'll work but I reckon it should.


  • Registered Users, Registered Users 2 Posts: 134 ✭✭d4v1d


    rock n' roll!

    worked a treat. thank you.


Advertisement