Re: Re: kxml / junit

Aleksander Slominski <[email protected]> Mon, 09 Feb 2004 01:49:51 -0500
Newsgroups gmane.text.xml.xmlpull.devel
Message-ID <[email protected]>
Stefan Haustein wrote:

>Aleksander Slominski wrote:
>  
>
>>so i was thinking we should have a property that sets serialzier 
>>processing model to XML version and is checked for complaiance with 
>>startDocument. by default it is XML 1.0 and if _optional_ property is 
>>supported than verion can be switched to 1.1.
>>    
>>
>
>Can we change this to make the more restricted version optional? All 
>those checks sum up, and I am still targeting J2ME... :) Do you know if 
>there are other relaxations in 1.1 that would allow to shrink the parser 
>size?
>  
>
AFAIK it is the only one chnage in XML 1.1 that makes parser simpler.

unfortunately in XML 1.1 they have also added a new requirement on EOL 
normalizations that complicates code ...

>I am not sure how exactly to handle this: Always escaping \n and \r 
>would mean to have no line breaks in the generated File(?). So do'nt we 
>need another method that adds an actual line break??
>  
>
i think serializer only need to escape \r, pass through \n and \t and 
otherwise throw error if ch <32.

for ch>=32 you need to take special care of &, < and any other chars do 
not fit into encoding if it is not UTF8.

here is what i have right now (just commited to XPP3 CVS):

    protected void writeElementContent(String text, Writer out) throws 
IOException
    {
        int pos = 0;
        for (int i = 0; i < text.length(); i++)
        {
            char ch = text.charAt(i);
            if(ch == ']') {
                if(seenBracket) {
                    seenBracketBracket = true;
                } else {
                    seenBracket = true;
                }
            } else {
                if(ch == '&') {
                    if(i > pos) out.write(text.substring(pos, i));
                    out.write("&amp;");
                    pos = i + 1;
                } else if(ch == '<') {
                    if(i > pos) out.write(text.substring(pos, i));
                    out.write("&lt;");
                    pos = i + 1;
                } else if(seenBracketBracket && ch == '>') {
                    if(i > pos) out.write(text.substring(pos, i));
                    out.write("&gt;");
                    pos = i + 1;
                } else if(ch < 32) {
                    //in XML 1.0 only legal character are #x9 | #xA | #xD
                    if(ch == 10 || ch == 9) { // \n and \t can pass through
                        // pass through
                    } else if(ch == 13) {
                        if(i > pos) out.write(text.substring(pos, i));
                        out.write("&#");
                        out.write(Integer.toString(ch));
                        out.write(';');
                        pos = i + 1;
                    } else { // \n and \t can pass through
                        throw new IllegalStateException(
                            "character "+Integer.toString(ch)+" is not 
allowed in output"+getLocation());
                        // in XML 1.1 legal are [#x1-#xD7FF]
                        //              if(ch > 0) {
                        //                  if(i > pos) 
out.write(text.substring(pos, i));
                        //                  out.write("&#");
                        //                  out.write(Integer.toString(ch));
                        //                  out.write(';');
                        //                  pos = i + 1;
                        //              } else {
                        //              throw new IllegalStateException(
                        //                  "character zero is not 
allowed in XML 1.1 output"+getLocation());
                        //              }
                    }
                }
                if(seenBracket) {
                    seenBracketBracket = seenBracket = false;
                }
               
            }
        }
        if(pos > 0) {
            out.write(text.substring(pos));
        } else {
            out.write(text);  // this is shortcut to the most common case
        }
    }

>Also, what should we do if someone includes illegal text (e.g. "-->") in 
>comment() or cdata()??
>  
>
i would not check for it ...

>I would like to throw an exception in the cdata case 
>
OK

>and to replace '-' 
>by '=' or similar in the comments(?)
>
that i think would be overkill - i think throwing exception is just fine ...

thanks,

alek

-- 
The best way to predict the future is to invent it - Alan Kay



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/xmlpull-dev/

<*> To unsubscribe from this group, send an email to:
     [email protected]

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/