Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / October 2006

Tip: Looking for answers? Try searching our database.

Deserializing xml into an object using xsl:copy-of

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Kenny D - 30 Oct 2006 23:09 GMT
Sample input XML...

<Publication>
   <FilingMetadata>
       <Id>38EA51240E6643208DB1B6D52F779A82</Id>
       <Cycle>BC</Cycle>
   </FilingMetadata>
   <PublicationComponent Role="Main" MediaType="Text">
       <TextContentItem>
           <Language>en-us</Language>
           <DataContent>
               <nitf>
                   <body.content>
                       <block>
                           <p>The dollar dropped versus the yen again
Thursday, extending the sharp losses seen in recent

sessions amid a violent reversal from months of betting heavily against
the Japanese currency.</p>
                           <p>However, the dollar gained modestly
against the euro, helped by solid economic data and also aided by the

yen's advance versus the euro.</p>
                       </block>
                   </body.content>
               </nitf>
           </DataContent>
       </TextContentItem>
   </PublicationComponent>
<Publication>

Target Class into which I want to eventually deserialize the above
xml...

class Publication
{
   public string ID;      // Will contain
"38EA51240E6643208DB1B6D52F779A82"
   public string Cycle;   // will contain BC

   public string DataContentXML;
}

This is a two-step process.

Step one is to use an xslt to transform the input into something like
this:

<TextContent>
   <Id>38EA51240E6643208DB1B6D52F779A82</id>
   <FullText>
       <nitf>
           <body.content>
               <block>
                   <p>The dollar dropped versus the yen again
Thursday, extending the sharp losses seen in recent sessions amid a
violent

reversal from months of betting heavily against the Japanese
currency.</p>
                           <p>However, the dollar gained modestly
against the euro, helped by solid economic data and also aided by the

yen's advance versus the euro.</p>
               </block>
           </body.content>
       </nitf>
   </FullText>
<TextContent>

The <ID> and <Cycle> tags works just fine.

I want to use xsl:copy-of (I think) to get all of the contents of the
<DataContent> tag, including xml tags loaded into a string so that all
tags are preserved.

Xsl:copy-of is not working.  All I get is "There is an error in the XML
file" with no further explanation.  If I use xsl:value-of, I can get
all the text but no tags.  The tags are important for later processing.

Step two will be to deserialize the xml above into an object as
outlined in the Publication class with everything between the
<FullText> tags loaded into the Publication.DataContentXML property as
one complete string, including the child tags.

I am not yet an XML or XSLT expert.

Question 1: Is this possible?
Question 2: How do I do this?
Oleg Tkachenko [MVP] - 31 Oct 2006 09:21 GMT
> Step one is to use an xslt to transform the input into something like
> this:
[quoted text clipped - 30 lines]
> file" with no further explanation.  If I use xsl:value-of, I can get
> all the text but no tags.  The tags are important for later processing.

Show us your XSLt stylesheet. That's hard to say why xsl:copy-of won't
work without seeing your code.

Signature

Oleg Tkachenko [XML MVP, MCPD]
http://blog.tkachenko.com | http://www.XmlLab.Net | http://www.XLinq.Net


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.