List Info

Thread: KoXmlReader




KoXmlReader
user name
2006-12-25 17:04:25
Hi,

In KFormula 2 we want to switch from QDom* classes to
KoXmlReader and 
KoXmlWriter for loading and saving. We have also a method in
a base class 
that does the task of reading all the attributes of each
element. The problem 
is that we use QDomNode::attributes() method but there's no
such a method in 
KoXmlNode. Is there any plan to add such method or should I
think about a 
workaround ?

Thanks
-- 
Alfredo Beaumont Sainz
http://www.al
fredobeaumont.org/blog.cgi
_______________________________________________
koffice-devel mailing list
koffice-develkde.org
h
ttps://mail.kde.org/mailman/listinfo/koffice-devel
KoXmlReader
user name
2006-12-25 19:16:14
> In KFormula 2 we want to switch from QDom* classes to
KoXmlReader and
> KoXmlWriter for loading and saving. We have also a
method in a base class
> that does the task of reading all the attributes of
each element. The problem
> is that we use QDomNode::attributes() method but
there's no such a method in
> KoXmlNode. Is there any plan to add such method or
should I think about a
> workaround ?

Good news !

As for QDomNodeMap necessary for QDomNode::attributes(),
implementing
this would make the whole node a bit heavier. I must think
for a way
to do this without losing the lightweightness of
KoXmlReader. So I'd
rather not implement it unless it's absolutely necessary.

Looking at how QDomNode::attributes() used in KFormula, how
about the
following workaround? First I'm going to implement function
attributeNames() in the namespace KoXml which returns a
QStringList
containing the name of all attributes (this way,
KoXml::attributeNames() can also work if we use the
fall-back QDom).
Then you can iterate for each name and get the attribute
value.

The pseudo-code will be:

QStringList attrList = KoXml::attributeNames(node);
foreach(QString attrName, attrList)
{
  QString attrValue = node.attribute(attrName);

  // do something with attribute name and value
}

Is that good enough?


Regards,

Ariya
_______________________________________________
koffice-devel mailing list
koffice-develkde.org
h
ttps://mail.kde.org/mailman/listinfo/koffice-devel
KoXmlReader
user name
2006-12-25 19:58:46
Astelehena 25 Abendua 2006 20:16(e)an, Ariya Hidayat(e)k
idatzi zuen:
> > In KFormula 2 we want to switch from QDom* classes
to KoXmlReader and
> > KoXmlWriter for loading and saving. We have also a
method in a base class
> > that does the task of reading all the attributes
of each element. The
> > problem is that we use QDomNode::attributes()
method but there's no such
> > a method in KoXmlNode. Is there any plan to add
such method or should I
> > think about a workaround ?
>
> Good news !
>
> As for QDomNodeMap necessary for
QDomNode::attributes(), implementing
> this would make the whole node a bit heavier. I must
think for a way
> to do this without losing the lightweightness of
KoXmlReader. So I'd
> rather not implement it unless it's absolutely
necessary.
>
> Looking at how QDomNode::attributes() used in KFormula,
how about the
> following workaround? First I'm going to implement
function
> attributeNames() in the namespace KoXml which returns a
QStringList
> containing the name of all attributes (this way,
> KoXml::attributeNames() can also work if we use the
fall-back QDom).
> Then you can iterate for each name and get the
attribute value.
>
> The pseudo-code will be:
>
> QStringList attrList = KoXml::attributeNames(node);
> foreach(QString attrName, attrList)
> {
>   QString attrValue = node.attribute(attrName);
>
>   // do something with attribute name and value
> }
>
> Is that good enough?

Sounds perfect!

-- 
Alfredo Beaumont Sainz
http://www.al
fredobeaumont.org/blog.cgi
_______________________________________________
koffice-devel mailing list
koffice-develkde.org
h
ttps://mail.kde.org/mailman/listinfo/koffice-devel
KoXmlReader
user name
2006-12-26 10:33:00
Done already. You can use KoXml::attributeNames() now, see
example in
libs/store/tests/koxmlreadertest.cpp.

Please let me know if you need anything else.

As soon as I got write access to our wiki, I'll write some
short
text/notice on how to port existing QDom code to
KoXmlReader.

Regards,

Ariya
_______________________________________________
koffice-devel mailing list
koffice-develkde.org
h
ttps://mail.kde.org/mailman/listinfo/koffice-devel
KoXmlReader
user name
2006-12-26 21:25:47
> As soon as I got write access to our wiki, I'll write
some short
> text/notice on how to port existing QDom code to
KoXmlReader.

It is now available in:
h
ttp://wiki.koffice.org/index.php?title=KoXmlReader



Regards,

Ariya
_______________________________________________
koffice-devel mailing list
koffice-develkde.org
h
ttps://mail.kde.org/mailman/listinfo/koffice-devel
KoXmlReader
user name
2006-12-26 22:37:02
Asteartea 26 Abendua 2006 22:25(e)an, Ariya Hidayat(e)k
idatzi zuen:
> > As soon as I got write access to our wiki, I'll
write some short
> > text/notice on how to port existing QDom code to
KoXmlReader.
>
> It is now available in:
> h
ttp://wiki.koffice.org/index.php?title=KoXmlReader

Thanks for the docs !

I see a problem to use it with KFormula though.
Documentation says KoXmlReader 
is read-only, and there's a pair of places where I did a
small QDom 
manipulation due to MathML defining some equivalent
notation. Is there an 
easy way I can handle this ? Is it possible, for example, to
do some quick 
KoXmlReader -> QDom -> KoXmlReader of a subtree ?
Otherwise I can just avoid 
that QDom manipulation.

Cheers
-- 
Alfredo Beaumont Sainz
http://www.al
fredobeaumont.org/blog.cgi
_______________________________________________
koffice-devel mailing list
koffice-develkde.org
h
ttps://mail.kde.org/mailman/listinfo/koffice-devel
KoXmlReader
user name
2006-12-26 22:44:44
> I see a problem to use it with KFormula though.
Documentation says KoXmlReader
> is read-only, and there's a pair of places where I did
a small QDom
> manipulation due to MathML defining some equivalent
notation. Is there an
> easy way I can handle this ? Is it possible, for
example, to do some quick
> KoXmlReader -> QDom -> KoXmlReader of a subtree ?
Otherwise I can just avoid
> that QDom manipulation.

No, that's currently not possible.

Could you please point out the code which does that
manipulation?
Perhaps I can then think of some workaround.

Regards,

Ariya
_______________________________________________
koffice-devel mailing list
koffice-develkde.org
h
ttps://mail.kde.org/mailman/listinfo/koffice-devel
KoXmlReader
user name
2006-12-26 23:17:42
Asteartea 26 Abendua 2006 23:44(e)an, Ariya Hidayat(e)k
idatzi zuen:
> > I see a problem to use it with KFormula though.
Documentation says
> > KoXmlReader is read-only, and there's a pair of
places where I did a
> > small QDom manipulation due to MathML defining
some equivalent notation.
> > Is there an easy way I can handle this ? Is it
possible, for example, to
> > do some quick KoXmlReader -> QDom ->
KoXmlReader of a subtree ? Otherwise
> > I can just avoid that QDom manipulation.
>
> No, that's currently not possible.
>
> Could you please point out the code which does that
manipulation?
> Perhaps I can then think of some workaround.


bracketelement.cc (in 1.6 branch, not yet in trunk) -> 
BracketElement::readContentFromMathMLDom()

from

// if it's a mfence tag, we need to convert to equivalent
expanded form.
// See section 3.3.8

to the end of the block (forget about the while loops, that
will change to 
foreach). Basically it does the following conversion. From:

<mfenced>
 <mi>x</mi>
 <mi>y</mi>
</mfenced>

to:

<mo>(</mo>
<mrow>
 <mi>x</mi>
 <mo>,</mo>
 <mi>y</mi>
</mrow>
<mo>)</mo>

Anyway, not sure that conversion instead of parsing twice
worths a change in 
KoXmlReader.

Cheers!
-- 
Alfredo Beaumont Sainz
http://www.al
fredobeaumont.org/blog.cgi
_______________________________________________
koffice-devel mailing list
koffice-develkde.org
h
ttps://mail.kde.org/mailman/listinfo/koffice-devel
KoXmlReader
user name
2006-12-27 12:33:46
On Tuesday 26 December 2006 22:25, Ariya Hidayat wrote:
> It is now available in:
> h
ttp://wiki.koffice.org/index.php?title=KoXmlReader

Your example code doesn't use any named nodes; which means
the ordering of the 
nodes is relevant. (=fragile) Also it uses
firstChild().toElement();

Would you mind updating the example by using the equivalent
of
the QDomNode method;
QDomElement   firstChildElement (const QString
&tagName=QString()) const

so;
   spreadsheetElement =
bodyElement.firstChild().toElement();
becomes;
   spreadsheetElement =
bodyElement.firstChildElement("sheet");

Cheers!
-- 
Thomas Zander
_______________________________________________
koffice-devel mailing list
koffice-develkde.org
h
ttps://mail.kde.org/mailman/listinfo/koffice-devel
KoXmlReader
user name
2007-01-01 08:55:34
> to the end of the block (forget about the while loops,
that will change to
> foreach). Basically it does the following conversion.
From:
>
> <mfenced>
>  <mi>x</mi>
>  <mi>y</mi>
> </mfenced>
>
> to:
>
> <mo>(</mo>
> <mrow>
>  <mi>x</mi>
>  <mo>,</mo>
>  <mi>y</mi>
> </mrow>
> <mo>)</mo>
>
> Anyway, not sure that conversion instead of parsing
twice worths a change in
> KoXmlReader.

This is difficult to implement in KoXmlReader.

Do you have any other workaround (in kformula)? Or that
two-pass
parsing is the intended workaround already ?

Regards,

Ariya
_______________________________________________
koffice-devel mailing list
koffice-develkde.org
h
ttps://mail.kde.org/mailman/listinfo/koffice-devel
[1-10] [11-12]

about | contact  Other archives ( Real Estate discussion Medical topics )