Thread: [Simple-support] Deserialize xml element as string
Brought to you by:
niallg
|
From: EECOLOR <ee...@gm...> - 2010-04-20 21:25:50
|
Hello, I want to deserialize the following xml: <?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> <title type="text">dive into mark</title> <entry> <title>Atom draft-07 snapshot</title> <content type="xhtml" xml:lang="en" xml:base="http://diveintomark.org/ "> <div xmlns="http://www.w3.org/1999/xhtml"> <p><i>[Update: The Atom draft is finished.]</i></p> </div> </content> </entry> </feed> I want to have the content as a string since it contains xhtml. Is there a possibility to have the div and it's content as string? Resulting in an object like this: class Entry { @Text String title; @? String content; } Thanks! Greetz Erik |
|
From: Niall G. <gal...@ya...> - 2010-04-20 22:08:00
|
Hi
There are a number of ways, but unfortunately it can not be done automatically. If you declared the following
.class Entry{ @Text
String title;
@Element
@Convert(MyAttemptAtCreatingAStringConverter.class) String content;
}
You would then have to try to convert to a string. However you would have to traverse the <entry> element using an InputNode. So it would not give you the string from the source document.
Alternatively, you could use the following XML.
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">dive into mark</title> <entry><![CDATA[
<title>Atom draft-07 snapshot</title>
<content type="xhtml" xml:lang="en"xml:base="http://diveintomark.org/"> <div xmlns="http://www.w3.org/1999/xhtml"> <p><i>[Update: The Atom draft is finished.]</i></p> </div> </content>
]]></entry>
</feed>
The CDATA section could then be taken in as an @Element(data=true).
Niall
--- On Tue, 4/20/10, EECOLOR <ee...@gm...> wrote:
From: EECOLOR <ee...@gm...>
Subject: [Simple-support] Deserialize xml element as string
To: sim...@li...
Date: Tuesday, April 20, 2010, 2:25 PM
Hello,
I want to deserialize the following xml:
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title type="text">dive into mark</title>
<entry>
<title>Atom draft-07 snapshot</title>
<content type="xhtml" xml:lang="en" xml:base="http://diveintomark.org/">
<div xmlns="http://www.w3.org/1999/xhtml"> <p><i>[Update: The Atom draft is finished.]</i></p>
</div> </content>
</entry>
</feed>
I want to have the content as a string since it contains xhtml. Is there a possibility to have the div and it's content as string?
Resulting in an object like this:
class Entry
{ @Text
String title;
@?
String content;
}
Thanks!
Greetz Erik
-----Inline Attachment Follows-----
------------------------------------------------------------------------------
-----Inline Attachment Follows-----
_______________________________________________
Simple-support mailing list
Sim...@li...
https://lists.sourceforge.net/lists/listinfo/simple-support
|
|
From: EECOLOR <ee...@gm...> - 2010-04-21 20:20:07
|
(I noticed the reply went to Niall, so resending to list) Thanks for your response! I wish I could alter the xml, but I do not have control over the specification of atom, hehe: http://tools.ietf.org/html/rfc4287 Is there another way besides traversing the InputNode? It seems inefficient to let Simple convert it to xml only to have me convert it back to a string. Greetz Erik On Wed, Apr 21, 2010 at 12:07 AM, Niall Gallagher <gal...@ya... > wrote: > Hi > > There are a number of ways, but unfortunately it can not be done > automatically. If you declared the following > > .class Entry > { > @Text > String title; > > @Element > @Convert(MyAttemptAtCreatingAStringConverter.class) > String content; > } > > You would then have to try to convert to a string. However you would have > to traverse the <entry> element using an InputNode. So it would not give you > the string from the source document. > > Alternatively, you could use the following XML. > > <?xml version="1.0" encoding="utf-8"?> > <feed xmlns="http://www.w3.org/2005/Atom"> > <title type="text">dive into mark</title> > <entry><![CDATA[ > > <title>Atom draft-07 snapshot</title> > <content type="xhtml" xml:lang="en"xml:base=" > http://diveintomark.org/"> > <div xmlns="http://www.w3.org/1999/xhtml"> > <p><i>[Update: The Atom draft is finished.]</i></p> > </div> > </content> > ]]></entry> > </feed> > > The CDATA section could then be taken in as an @Element(data=true). > > Niall > |
|
From: EECOLOR <ee...@gm...> - 2010-04-21 20:20:47
|
I am now trying to traverse the elements, but I am running into trouble when
I encounter stuff like:
<content>
text <i>text</i> text
</content>
*
*
Any suggestions?*
*
Thanks!
Greetz Erik
On Wed, Apr 21, 2010 at 12:16 AM, EECOLOR <ee...@gm...> wrote:
> Thanks for your response!
>
> I wish I could alter the xml, but I do not have control over the
> specification of atom, hehe: http://tools.ietf.org/html/rfc4287
>
> Is there another way besides traversing the InputNode? It seems inefficient
> to let Simple convert it to xml only to have me convert it back to a string.
>
>
> Greetz Erik
>
>
> On Wed, Apr 21, 2010 at 12:07 AM, Niall Gallagher <
> gal...@ya...> wrote:
>
>> Hi
>>
>> There are a number of ways, but unfortunately it can not be done
>> automatically. If you declared the following
>>
>> .class Entry
>> {
>> @Text
>> String title;
>>
>> @Element
>> @Convert(MyAttemptAtCreatingAStringConverter.class)
>> String content;
>> }
>>
>> You would then have to try to convert to a string. However you would have
>> to traverse the <entry> element using an InputNode. So it would not give you
>> the string from the source document.
>>
>> Alternatively, you could use the following XML.
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <feed xmlns="http://www.w3.org/2005/Atom">
>> <title type="text">dive into mark</title>
>> <entry><![CDATA[
>>
>> <title>Atom draft-07 snapshot</title>
>> <content type="xhtml" xml:lang="en"xml:base="
>> http://diveintomark.org/">
>> <div xmlns="http://www.w3.org/1999/xhtml">
>> <p><i>[Update: The Atom draft is finished.]</i></p>
>> </div>
>> </content>
>> ]]></entry>
>> </feed>
>>
>> The CDATA section could then be taken in as an @Element(data=true).
>>
>> Niall
>>
>> --- On *Tue, 4/20/10, EECOLOR <ee...@gm...>* wrote:
>>
>>
>> From: EECOLOR <ee...@gm...>
>> Subject: [Simple-support] Deserialize xml element as string
>> To: sim...@li...
>> Date: Tuesday, April 20, 2010, 2:25 PM
>>
>>
>> Hello,
>>
>> I want to deserialize the following xml:
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <feed xmlns="http://www.w3.org/2005/Atom">
>> <title type="text">dive into mark</title>
>> <entry>
>> <title>Atom draft-07 snapshot</title>
>> <content type="xhtml" xml:lang="en" xml:base="
>> http://diveintomark.org/">
>> <div xmlns="http://www.w3.org/1999/xhtml">
>> <p><i>[Update: The Atom draft is finished.]</i></p>
>> </div>
>> </content>
>> </entry>
>> </feed>
>>
>> I want to have the content as a string since it contains xhtml. Is there a
>> possibility to have the div and it's content as string?
>> Resulting in an object like this:
>>
>> class Entry
>> {
>> @Text
>> String title;
>>
>> @?
>> String content;
>> }
>>
>> Thanks!
>>
>>
>> Greetz Erik
>>
>> -----Inline Attachment Follows-----
>>
>>
>> ------------------------------------------------------------------------------
>>
>> -----Inline Attachment Follows-----
>>
>> _______________________________________________
>> Simple-support mailing list
>> Sim...@li...<http://mc/compose?to=...@li...>
>> https://lists.sourceforge.net/lists/listinfo/simple-support
>>
>>
>>
>
|
|
From: Niall G. <gal...@ya...> - 2010-04-21 20:27:39
|
Well, there is a really ugly way to do this. You can grab the StAX event or DOM node from InputNode.getSource(), a real hack, but it works. The reason you can't do this with Simple is because it is not canonical XML. Which is what Simple XML is all about. --- On Wed, 4/21/10, EECOLOR <ee...@gm...> wrote: From: EECOLOR <ee...@gm...> Subject: Re: [Simple-support] Deserialize xml element as string To: sim...@li... Date: Wednesday, April 21, 2010, 1:20 PM I am now trying to traverse the elements, but I am running into trouble when I encounter stuff like: <content> text <i>text</i> text </content> Any suggestions? Thanks! Greetz Erik On Wed, Apr 21, 2010 at 12:16 AM, EECOLOR <ee...@gm...> wrote: Thanks for your response! I wish I could alter the xml, but I do not have control over the specification of atom, hehe: http://tools.ietf.org/html/rfc4287 Is there another way besides traversing the InputNode? It seems inefficient to let Simple convert it to xml only to have me convert it back to a string. Greetz Erik On Wed, Apr 21, 2010 at 12:07 AM, Niall Gallagher <gal...@ya...> wrote: Hi There are a number of ways, but unfortunately it can not be done automatically. If you declared the following .class Entry{ @Text String title; @Element @Convert(MyAttemptAtCreatingAStringConverter.class) String content; } You would then have to try to convert to a string. However you would have to traverse the <entry> element using an InputNode. So it would not give you the string from the source document. Alternatively, you could use the following XML. <?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> <title type="text">dive into mark</title> <entry><![CDATA[ <title>Atom draft-07 snapshot</title> <content type="xhtml" xml:lang="en"xml:base="http://diveintomark.org/"> <div xmlns="http://www.w3.org/1999/xhtml"> <p><i>[Update: The Atom draft is finished.]</i></p> </div> </content> ]]></entry> </feed> The CDATA section could then be taken in as an @Element(data=true). Niall --- On Tue, 4/20/10, EECOLOR <ee...@gm...> wrote: From: EECOLOR <ee...@gm...> Subject: [Simple-support] Deserialize xml element as string To: sim...@li... Date: Tuesday, April 20, 2010, 2:25 PM Hello, I want to deserialize the following xml: <?xml version="1.0" encoding="utf-8"?> <feed xmlns="http://www.w3.org/2005/Atom"> <title type="text">dive into mark</title> <entry> <title>Atom draft-07 snapshot</title> <content type="xhtml" xml:lang="en" xml:base="http://diveintomark.org/"> <div xmlns="http://www.w3.org/1999/xhtml"> <p><i>[Update: The Atom draft is finished.]</i></p> </div> </content> </entry> </feed> I want to have the content as a string since it contains xhtml. Is there a possibility to have the div and it's content as string? Resulting in an object like this: class Entry { @Text String title; @? String content; } Thanks! Greetz Erik -----Inline Attachment Follows----- ------------------------------------------------------------------------------ -----Inline Attachment Follows----- _______________________________________________ Simple-support mailing list Sim...@li... https://lists.sourceforge.net/lists/listinfo/simple-support -----Inline Attachment Follows----- ------------------------------------------------------------------------------ -----Inline Attachment Follows----- _______________________________________________ Simple-support mailing list Sim...@li... https://lists.sourceforge.net/lists/listinfo/simple-support |
|
From: EECOLOR <ee...@gm...> - 2010-04-21 21:07:04
|
(somehow my reply button does not reply to the list, so sorry for any doubles) Thanks for you help so far. I tried that route, but it seems only start events are passed into the Converter... I might be mistaken on that though. On Wed, Apr 21, 2010 at 10:27 PM, Niall Gallagher <gal...@ya... > wrote: > Well, there is a really ugly way to do this. You can grab the StAX event or > DOM node from InputNode.getSource(), a real hack, but it works. The reason > you can't do this with Simple is because it is not canonical XML. Which is > what Simple XML is all about. > > > --- On *Wed, 4/21/10, EECOLOR <ee...@gm...>* wrote: > > > From: EECOLOR <ee...@gm...> > Subject: Re: [Simple-support] Deserialize xml element as string > > To: sim...@li... > Date: Wednesday, April 21, 2010, 1:20 PM > > > I am now trying to traverse the elements, but I am running into trouble > when I encounter stuff like: > > <content> > text <i>text</i> text > </content> > * > * > Any suggestions?* > * > > Thanks! > > > Greetz Erik > > |
|
From: <nia...@rb...> - 2010-04-26 08:30:50
|
Hi,
Thanks, ill take a look at this, looks like it could be a very useful feature.
Niall
Niall Gallagher
RBS Global Banking & Markets
Office: +44 2070851454
________________________________
From: EECOLOR [mailto:ee...@gm...]
Sent: 25 April 2010 01:08
To: sim...@li...
Subject: Re: [Simple-support] Deserialize xml element as string
It's quite tricky stuff. I managed to create a patch (see attachment) that adds a method 'getXMLString' to InputNode. The implementation for the DocumentReader is ok, for the StreamReader however I have some concerns. In the StreamReader the events are gathered and placed into the StreamReader.Start EventNodes. I an not sure what the impact of this approach is on memory and performance. I think it would be nice to have a switch to turn it on and off. Any ideas on this?
The getXMLString method can be used in a converter like this:
public String read(InputNode node) throws Exception {
while (node.getNext() != null) {
/*
* make sure all nodes are visited before we get the xml string
*
* this is only needed for StAX
*/
}
String xmlString = node.getXMLString();
return xmlString== null ? "" : xmlString;
}
The patch uses the 'src' directory as root.
Last, but not least: the source code looks amazing. Really a perfect job and a very nice architecture.
Greetz Erik
On Wed, Apr 21, 2010 at 11:06 PM, EECOLOR <ee...@gm...<mailto:ee...@gm...>> wrote:
(somehow my reply button does not reply to the list, so sorry for any doubles)
Thanks for you help so far.
I tried that route, but it seems only start events are passed into the Converter...
I might be mistaken on that though.
***********************************************************************************
The Royal Bank of Scotland plc. Registered in Scotland No 90312.
Registered Office: 36 St Andrew Square, Edinburgh EH2 2YB.
Authorised and regulated by the Financial Services Authority. The
Royal Bank of Scotland N.V. is authorised and regulated by the
De Nederlandsche Bank and has its seat at Amsterdam, the
Netherlands, and is registered in the Commercial Register under
number 33002587. Registered Office: Gustav Mahlerlaan 10,
Amsterdam, The Netherlands. The Royal Bank of Scotland N.V. and
The Royal Bank of Scotland plc are authorised to act as agent for each
other in certain jurisdictions.
This e-mail message is confidential and for use by the addressee only.
If the message is received by anyone other than the addressee, please
return the message to the sender by replying to it and then delete the
message from your computer. Internet e-mails are not necessarily
secure. The Royal Bank of Scotland plc and The Royal Bank of Scotland
N.V. including its affiliates ("RBS group") does not accept responsibility
for changes made to this message after it was sent.
Whilst all reasonable care has been taken to avoid the transmission of
viruses, it is the responsibility of the recipient to ensure that the onward
transmission, opening or use of this message and any attachments will
not adversely affect its systems or data. No responsibility is accepted
by the RBS group in this regard and the recipient should carry out such
virus and other checks as it considers appropriate.
Visit our website at www.rbs.com
***********************************************************************************
|
|
From: Dawid G. <daw...@gm...> - 2011-02-18 09:32:12
|
Hi, can we hope for getXMLString in official Simple release? niall.gallagher wrote: > > Hi, > > Thanks, ill take a look at this, looks like it could be a very useful > feature. > > Niall > > -- View this message in context: http://old.nabble.com/Deserialize-xml-element-as-string-tp28309099p30957074.html Sent from the Simple XML Serialization mailing list archive at Nabble.com. |
|
From: Niall G. <gal...@ya...> - 2011-03-16 10:48:00
|
Yes, Ill make sure to integrate this. There is a patch for this I will attempt to integrate it. Sorry for late response, this got caught by my spam detector. --- On Fri, 18/2/11, Dawid Gorniak <daw...@gm...> wrote: > From: Dawid Gorniak <daw...@gm...> > Subject: Re: [Simple-support] Deserialize xml element as string > To: sim...@li... > Received: Friday, 18 February, 2011, 1:32 AM > > Hi, > can we hope for getXMLString in official Simple release? > > > niall.gallagher wrote: > > > > Hi, > > > > Thanks, ill take a look at this, looks like it could > be a very useful > > feature. > > > > Niall > > > > > > -- > View this message in context: http://old.nabble.com/Deserialize-xml-element-as-string-tp28309099p30957074.html > Sent from the Simple XML Serialization mailing list archive > at Nabble.com. > > > ------------------------------------------------------------------------------ > Colocation vs. Managed Hosting > A question and answer guide to determining the best fit > for your organization - today and in the future. > http://p.sf.net/sfu/internap-sfd2d > _______________________________________________ > Simple-support mailing list > Sim...@li... > https://lists.sourceforge.net/lists/listinfo/simple-support > |