[prev in list] [next in list] [prev in thread] [next in thread] 

List:       koffice-devel
Subject:    Re: KoXmlWriter: A problem in combination of the content written by
From:       Matus Uzak <matus.uzak () ixonos ! com>
Date:       2010-08-02 10:43:39
Message-ID: op.vgs321p9xo1g39 () jamaica
[Download RAW message or body]

Hi,

> Why are you using 2 writers, One writer is enough.

Well just a matter of simplicity and consistency.  I could of course share  
one global writer in the code
and check a few variables for context but this would mess up the code.   
I'm collecting the content for
the hyperlink element and inserting corresponding bookmarks into a  
temporary writer, because I don't know
if this is going to be an image (<draw:a> required) or text (<text:a>  
required).

When I'm using addCompleteElement to add the CONTENT wrote by the  
temporary writer, the result is following:
newline space CONTENT space.  The second space is added by calling  
endElement.  KoXmlWriter is just doing
this to keep the resulting xml look nice, which is not desired in my case.

I will try to redesign the code to use just one KoXmlWriter, shouldn't be  
that bad.

br,

matus

On Sat, 31 Jul 2010 06:33:24 +0200, Thorsten Zachmann  
<t.zachmann@zagge.de> wrote:

> Hello,
>
> On Friday 30 July 2010 15:42:44 Matus Uzak wrote:
>> I'm using two KoXmlWriter type writers to construct the following:
>>
>> <text:a xlink:type="simple"
>> xlink:href="http://google.com">http://google.co<text:bookmark-start
>> text:name="_Hlt250539236"/>m<text:bookmark-end
>> text:name="_Hlt250539236"/></text:a>
>>
>> The first writer is taking care of the <text:a> element and it's  
>> parents.
>> The second one is used to write plain text
>> potentially combined with several <text:bookmark> elements.
>>
>
> Why are you using 2 writers, One writer is enough. The following does  
> what you
> want:
>
>     writer->startElement("text:a");
>     writer->addAttribute("xlink:href", "http://google.com");
>     writer->addTextNode("http://google.co");
>     writer->startElement("text:bookmark-start");
>     writer->addAttribute("text:name", "_Hlt250539236");
>     writer->endElement();
>     writer->addTextNode("m");
>     writer->startElement("text:bookmark-end");
>     writer->addAttribute("text:name", "_Hlt250539236");
>     writer->endElement();
>     writer->endElement();
>
> Using one writer only has the benefit of using less resources and be much
> faster too.
>
>> PROBLEM:
>> --------
>>
>> There are two options to insert the buff2 content wrote by the second
>> writer:
>>
>> 1. Using addCompleteElement, which indents the buff2 content (NOT  
>> CORRECT
>> in this case!):
>>
>> writer.startElement("text:a");
>> writer.addAttribute("xlink:type", "simple");
>> writer.addAttribute("xlink:href", QUrl(*str).toEncoded());
>> writer.addCompleteElement(buff2);
>> writer.endElement();
>>
>> The result:
>>
>> <text:a xlink:type="simple" xlink:href="http://google.com">
>>   http://google.co<text:bookmark-start
>> text:name="_Hlt250539236"/>m<text:bookmark-end  
>> text:name="_Hlt250539236"/>
>> </text:a>
>>
>>
>> 2. Using addTextNode, which is calling escapeForXML (NOT CORRECT in this
>> case!):
>>
>> writer.startElement("text:a");
>> writer.addAttribute("xlink:type", "simple");
>> writer.addAttribute("xlink:href", QUrl(*str).toEncoded());
>> QString tmp = QString::fromUtf8(buff2.buffer(), buff2.buffer().size());
>> writer.addTextNode(tmp);
>> writer.endElement();
>>
>> The result:
>>
>> <text:a xlink:type="simple"
>> xlink:href="http://google.com">http://google.co&lt;text:bookmark-start
>> text:name="_Hlt250539236"/&gt;m&lt;text:bookmark-end
>> text:name="_Hlt250539236"/&gt;</text:a>
>>
>
> What exactly is the problem you are trying to solve? Using addTextNode  
> is not
> what you want to do you want to add a xml snippet for which  
> addCompleteElement
> should be used. The name might be misleading but it does what you want.
>
>> SOLUTION:
>> ---------
>>
>> I would like to overload the addTextNode function without using
>> escapeForXML or simply add another parameter, which would control the
>> usage of escapeForXML.
>> Any other suggestions or comments?
>
> Adding a text node needs to escape for XML so adding a bool there is just
> wrong . I think it makes no sense to misuse this function.
>
> The above might make no sense as I have not understood what the problem  
> is you
> are trying to solve. If so please try to explain it once more in more  
> detail.
>
> Thorsten
> _______________________________________________
> koffice-devel mailing list
> koffice-devel@kde.org
> https://mail.kde.org/mailman/listinfo/koffice-devel
>


-- 
Matus Uzak
Software Designer
Ixonos Slovakia s.r.o.
Sturova 27
040 01 Kosice, Slovakia
mobile 0421 918 718 958
email: matus.uzak@ixonos.com
http://www.ixonos.com

_______________________________________________
koffice-devel mailing list
koffice-devel@kde.org
https://mail.kde.org/mailman/listinfo/koffice-devel
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic