Re: [Simple-support] Element with both attributes and text body?
Brought to you by:
niallg
|
From: Niall G. <gal...@ya...> - 2007-04-01 17:39:14
|
Hi,
Seems like a nice way to do it. However I assume that such an annotation could not be used with elements? For instance:
<root>
<element attr="a">
Text
<element2>
Text
</element>
Text
</element>
</root>
For the above what would the text be? I think Ill probably implement the @Text annotation with the restriction that it can not be used with elements, and only one @Text annotation per class. So the only possible structure would be:
<element attr1="1" attrn="n"> Text</element>
Is this how .NET handles it?
Niall Gallagher
----- Original Message ----
From: Arne Claassen <arn...@cl...>
To: Niall Gallagher <gal...@ya...>
Sent: Friday, March 30, 2007 8:20:43 AM
Subject: Re: [Simple-support] Element with both attributes and text body?
Niall,
The way .NET handles it, is with an Attribute (i.e. Annotation) called
XmlTextAttribute like this:
[XmlText()]
public string text
So an annotation equivalent could be
@Text()
private String text;
The catch with this Annotation is that it can only be used once in any
class.
cheers,
arne
Niall Gallagher wrote:
>Hi Arne,
>
>Well this is something I was considering, however this comes down to a
>serialization versus deserialization issue. It would be simple to
>deserialize such a structure. For instance:
>
>
>
>@Root(name="myelement")
>
>public class MyObject {
>
>
> @Attribute(name="someAttribute")
> private String someAttribute;
>
>
>
> private String text;
>
>
>
> public MyObject(String text) {
>
> this.text = text;
>
> }
>
>}
>
>
>
>The difficulty is in serialization, how could the decision be made to
>serialize? I guess an additional annotation or interface telling the
>framework what action to take could be done? Currently though I have
>decided not to add support for this, at least until I can think of a
>decent way to implement it.
>
>Suggestions are welcome on how to approach this.
>
>
>
>Niall
>
>
>----- Original Message ----
>From: Arne Claassen <arn...@cl...>
>To: sim...@li...
>Sent: Wednesday, March 28, 2007 8:34:48 AM
>Subject: [Simple-support] Element with both attributes and text body?
>
>I just found Simple today. Excellent work on the project. Nice, simple,
>small. I usually work in C#, so Simple's syntax is very comfortable to
>me compared to .NET's attribute driven mark-up.
>
>Of course, I've already hit a stumbling block. Is there a way to define
>a class that has both Attributes and body text for an Element? I.e. I'm
>trying to create a class to represent:
>
><?xml version="1.0" encoding="UTF-8"?>
><message guid="ABDB9C3E-31B5-09B5-6E0F-5BC5F86BF5C7" type="default"
>utime="1175098850078">
> payload
></message>
>
>The closest I've figured out is:
>
><?xml version="1.0" encoding="UTF-8"?>
><message guid="ABDB9C3E-31B5-09B5-6E0F-5BC5F86BF5C7" type="default"
>utime="1175098850078">
> <data>payload</data>
></message>
>
>
>thanks,
>arne
>
>-------------------------------------------------------------------------
>Take Surveys. Earn Cash. Influence the Future of IT
>Join SourceForge.net's Techsay panel and you'll get the chance to share your
>opinions on IT & business topics through brief surveys-and earn cash
>http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
>_______________________________________________
>Simple-support mailing list
>Sim...@li...
>https://lists.sourceforge.net/lists/listinfo/simple-support
>
>
>
>
>
>
>____________________________________________________________________________________
>Expecting? Get great news right away with email Auto-Check.
>Try the Yahoo! Mail Beta.
>http://advision.webevents.yahoo.com/mailbeta/newmail_tools.html
>
>
>
____________________________________________________________________________________
Sucker-punch spam with award-winning protection.
Try the free Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/features_spam.html
|