[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: Thorsten Zachmann <t.zachmann () zagge ! de>
Date: 2010-07-31 4:33:24
Message-ID: 201007310633.25187.t.zachmann () zagge ! de
[Download RAW message or body]
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<text:bookmark-start
> text:name="_Hlt250539236"/>m<text:bookmark-end
> text:name="_Hlt250539236"/></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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic