Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Core » [solved] Extensions to Xmlize for arrays
[solved] Extensions to Xmlize for arrays [message #32484] Fri, 20 May 2011 11:59 Go to next message
cbpporter is currently offline  cbpporter
Messages: 1400
Registered: September 2007
Senior Contributor
I have small problem with Xmlize and containers. The XML will look like this:

<cats>
    <item>...</item>
    <item>...</item>
    ...
</cats>


That is not very XMLish. I want:
<cats>
    <cat>...</cat>
    <cat>...</cat>
    ...
</cats>


Could we add this to XmlIO class:
class XmlIO {
...

public:
...
	template <class T> XmlIO operator()(const char *tag, const char *itemtag, T& var);


and after:
template <class T>
void Xmlize(XmlIO xml, const char* itemtag, T& var)
{
	var.Xmlize(xml);
}

...

template <class T> XmlIO XmlIO::operator()(const char *tag, const char *itemtag, T& var) {
	XmlIO n(*this, tag);
	Xmlize(n, itemtag, var);
	return *this;
}

...

template<class T>
void Xmlize(XmlIO xml, const char* itemtag, Vector<T>& data)
{
	XmlizeContainer(xml, itemtag, data);
}

...

template<class T>
void Xmlize(XmlIO xml, const char* itemtag, Array<T>& data)
{
	XmlizeContainer(xml, itemtag, data);
}


This change is only meant for Array and Vector marshaling, but could be extended to rest of the containers.

So now I can do:

xml("cats", cats);


for the original XML format, or:

xml("cats", "cat", cats);

for the format I want.

[Updated on: Tue, 31 July 2018 11:44]

Report message to a moderator

Re: Extensions to Xmlize for arrays [message #32489 is a reply to message #32484] Fri, 20 May 2011 17:20 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

cbpporter wrote on Fri, 20 May 2011 12:59


This change is only meant for Array and Vector marshaling, but could be extended to rest of the containers.

So now I can do:

xml("cats", cats);


for the original XML format, or:

xml("cats", "cat", cats);

for the format I want.


What about if your Array cats have items with array type?
Re: Extensions to Xmlize for arrays [message #32501 is a reply to message #32484] Sun, 22 May 2011 19:18 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12565
Registered: November 2005
Ultimate Member
cbpporter wrote on Fri, 20 May 2011 05:59

I have small problem with Xmlize and containers. The XML will look like this:

<cats>
    <item>...</item>
    <item>...</item>
    ...
</cats>


That is not very XMLish. I want:
<cats>
    <cat>...</cat>
    <cat>...</cat>
    ...
</cats>


Could we add this to XmlIO class:
class XmlIO {
...

public:
...
	template <class T> XmlIO operator()(const char *tag, const char *itemtag, T& var);


and after:
template <class T>
void Xmlize(XmlIO xml, const char* itemtag, T& var)
{
	var.Xmlize(xml);
}

...

template <class T> XmlIO XmlIO::operator()(const char *tag, const char *itemtag, T& var) {
	XmlIO n(*this, tag);
	Xmlize(n, itemtag, var);
	return *this;
}

...

template<class T>
void Xmlize(XmlIO xml, const char* itemtag, Vector<T>& data)
{
	XmlizeContainer(xml, itemtag, data);
}

...

template<class T>
void Xmlize(XmlIO xml, const char* itemtag, Array<T>& data)
{
	XmlizeContainer(xml, itemtag, data);
}


This change is only meant for Array and Vector marshaling, but could be extended to rest of the containers.

So now I can do:

xml("cats", cats);


for the original XML format, or:

xml("cats", "cat", cats);

for the format I want.


I have no problem adding this. Could you post a complete patch please?

Mirek
Re: Extensions to Xmlize for arrays [message #32508 is a reply to message #32489] Mon, 23 May 2011 09:53 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1400
Registered: September 2007
Senior Contributor
tojocky wrote on Fri, 20 May 2011 18:20

cbpporter wrote on Fri, 20 May 2011 12:59


This change is only meant for Array and Vector marshaling, but could be extended to rest of the containers.

So now I can do:

xml("cats", cats);


for the original XML format, or:

xml("cats", "cat", cats);

for the format I want.


What about if your Array cats have items with array type?


Not a problem. My patch does not affect your serialization, since you need to write extra code to change the sub item name. But if you do, you will end up with:

<cats>
  <cat>
    ...
    <whiskers>
      <whisker>...
    </whiskers>
  </cat>
  <cat>
  ...
</cats>
Re: Extensions to Xmlize for arrays [message #32509 is a reply to message #32501] Mon, 23 May 2011 09:57 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1400
Registered: September 2007
Senior Contributor
mirek wrote on Sun, 22 May 2011 20:18


I have no problem adding this. Could you post a complete patch please?

Mirek


Sue, I'll upload the file as an attachment.
  • Attachment: Xmlize.h
    (Size: 9.50KB, Downloaded 218 times)
Re: Extensions to Xmlize for arrays [message #32555 is a reply to message #32509] Tue, 24 May 2011 18:01 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12565
Registered: November 2005
Ultimate Member
Patch applied, thank you.

Mirek
Re: Extensions to Xmlize for arrays [message #34201 is a reply to message #32555] Wed, 02 November 2011 08:33 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 736
Registered: January 2008
Location: Moscow, Russia
Contributor

Can you do analog decision for ArrayMap (maybe also VectorMap ...)?

SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}
Re: Extensions to Xmlize for arrays [message #34203 is a reply to message #34201] Wed, 02 November 2011 10:31 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1400
Registered: September 2007
Senior Contributor
sergeynikitin wrote on Wed, 02 November 2011 09:33

Can you do analog decision for ArrayMap (maybe also VectorMap ...)?


Sure, I'll look over it after I can check out a new nightly build.
Re: Extensions to Xmlize for arrays [message #34205 is a reply to message #34203] Wed, 02 November 2011 13:43 Go to previous messageGo to next message
sergeynikitin is currently offline  sergeynikitin
Messages: 736
Registered: January 2008
Location: Moscow, Russia
Contributor

I tried to do it myself, but there is some error. I did not understand, so far, due to lack of time and put off for later.

Until replaced by a direct search for Array. This is certainly the wrong way.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Wed, 02 November 2011 13:47]

Report message to a moderator

Re: Extensions to Xmlize for arrays [message #50115 is a reply to message #34205] Mon, 30 July 2018 16:31 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1400
Registered: September 2007
Senior Contributor
This is one crazy necro, but I'm still using "wrong" labels for vector sub-items.

What could we do to solve this issue?
Re: Extensions to Xmlize for arrays [message #50116 is a reply to message #50115] Mon, 30 July 2018 17:13 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12565
Registered: November 2005
Ultimate Member
What is your code?

Mirek
Re: Extensions to Xmlize for arrays [message #50117 is a reply to message #50116] Tue, 31 July 2018 10:01 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1400
Registered: September 2007
Senior Contributor
mirek wrote on Mon, 30 July 2018 18:13
What is your code?

Mirek

Well, here is the thing. I posted it way back. It worked for me. You said you applied it. sergeynikitin found some erros or other problems.

Time passed and I was forced to update U++ and remove the use of this code from the project. The code is lost. And there is something similar now in U++, but don't know exactly how to use it.

What does this do exactly:
template <class T> XmlIO List(const char *tag, const char *itemtag, T& var);


Best I can do is link to my old post: https:// www.ultimatepp.org/forums/index.php?t=msg&th=6032&go to=32509&#msg_32509
Re: Extensions to Xmlize for arrays [message #50118 is a reply to message #50117] Tue, 31 July 2018 11:06 Go to previous messageGo to next message
mirek is currently offline  mirek
Messages: 12565
Registered: November 2005
Ultimate Member
Yes, List solves this for arrays. If I remember well, there was some overloading issue that prevented plain operator() to be used here.

Now I guess you will request something similar for maps, correct? Smile
Re: Extensions to Xmlize for arrays [message #50120 is a reply to message #50118] Tue, 31 July 2018 11:40 Go to previous message
cbpporter is currently offline  cbpporter
Messages: 1400
Registered: September 2007
Senior Contributor
mirek wrote on Tue, 31 July 2018 12:06
Yes, List solves this for arrays. If I remember well, there was some overloading issue that prevented plain operator() to be used here.

Now I guess you will request something similar for maps, correct? Smile

Somewhere between "soon" and another 7 years Laughing.

Thank you! I'll give List a try. I've spent the last 3 days updating our XML configuration system and found that the resulting XMLs had this problem. It would be great if I can finally fix this.
Previous Topic: ONE and assignement
Next Topic: Folder for configuration file
Goto Forum:
  


Current Time: Thu Jul 02 11:38:10 CEST 2020

Total time taken to generate the page: 0.01427 seconds