Upgrading from SL1.1 to SL2.0
Last post 05-09-2008 3:33 AM by deepikaFO. 4 replies.
Sort Posts:
04-15-2008 10:28 AM
Upgrading from SL1.1 to SL2.0

Hello dear all,

I am new in Silverlight 2.0. I wrote an application using Silverlight 1.1, Blend and VS08. I must add that I used an .XML File to store the paths and other Informations of my SL Elements, and then call and control them via a Javascript File in order to use it in my .xaml. The point was that I wanted a non-programmer to be able to change easily a video or Image for eg in just opening the xml file, without having to know something about JS or XAML.  My question is: since there´s no more the default.html.js file (for the createSilverlight() Function), how can I retrieve the informations of the xml file in a JS File in Silverlight 2.0?
Another question is, does <DoubleAnimationUsingKeyFrames...><SplineDoubleKeyFrame KeyTime="00:00:07" Value="0"/> And so on still work with SL2.0 because I tried it, but no Storyboard work yet.

Thanks for your help,

Sylvie

Sylvie

Joined on 01-09-2008
Posts 26
04-15-2008 1:35 PM
Re: Upgrading from SL1.1 to SL2.0

Sylvie,

If I understand your question correctly, you would like to load and parse an external XML file in your SL application.  In Silverlight 2, resources are packaged into a XAP file which is downloaded by the Silverlight plugin.  A XAP file is essentially a zip file.  If you want to include your XML file, you can set the Build Action of your XML file to Content.  Doing this will cause your XML file to be packaged in the XAP file.  In your application you can load the XML file like so:

StreamResourceInfo si = Application.GetResourceStream(new Uri("MyFile.xml", UriKind.Relative));
StreamReader sr = new StreamReader(si.Stream);

If you do not wish to package the XML file inside of the XAP file, there are quite a few other options.  A few are listed below:

Embed the file into the SL assembly as an Resource.
Download the XML file from the server on the fly using WebClient.
Get the XML using a web service call.

If this has answered your question, please click on "Mark as Answer" on this post.

Thanks,
Page Brooks, MCSD, MCAD
PageBrooks.com | RSS Feed

pbrooks

Joined on 03-23-2006
Florence, SC
Posts 116
04-16-2008 9:55 AM
Re: Upgrading from SL1.1 to SL2.0

Hi PBrooks,

thanks for answering. I wrote your code, the problem now is that I don´t know how to use it further. I mean, ok I loaded the XML file in my application (It actually looks like:  

<?xml version="1.0" encoding="utf-8" ?>
<
Playlistitem GUID="7212c665-bbd7-45d3-996b-334a747eb6b2">
<
dtmCreated>2007-10-22T13:44:16</dtmCreated>
<
dtmLastModified>2007-10-22T13:44:16</dtmLastModified>
<
Fields>
<Field>
<
strType>SingleLine</strType>
<
lngOrderNumber>1</lngOrderNumber>
<strText>Tres bon vin Francais </strText>
</Field>

<Field>
<
strType>Price</strType>
<
lngOrderNumber>2</lngOrderNumber>
<
strText>7,99</strText>
</
Field>

<Field>
<
strType>Image</strType>
<
lngOrderNumber>3</lngOrderNumber>
<
strText>Images/Chateau.png</strText>
</
Field>

</Fields></Playlistitem>

 Moreover I loaded the XML file in a Javascript file with:
xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=
false;
xmlDoc.load(pXmlFileName);
p1_parseXml();

And got the Items with
try{
strType = item.getElementsByTagName(
"lngOrderNumber")[0].firstChild.nodeValue;
strValue = item.getElementsByTagName(
"strText")[0].firstChild.nodeValue;
}

The Question is how do I get the items from my XML-File with your code? I use the C#-code-behind and I was more at ease with JavaScript. Or do you think I can still add my JS-File in my project to load and get the Items from my xml File?

Thanks a lot for answering,

 Sylvie

Sylvie

Joined on 01-09-2008
Posts 26
04-16-2008 12:54 PM
Marked as Answer
Re: Upgrading from SL1.1 to SL2.0

 Sylvie,

There are many different ways you could approach this.  Personally, I would use LINQ to parse the XML into an object.  Please see my code below:

// Load the XML document into a stream.
StreamResourceInfo si = Application.GetResourceStream(new Uri("MyFile.xml", UriKind.Relative));
StreamReader sr = new StreamReader(si.Stream);

// Build an XDocument from the XML data.
// XDocument is in the System.Xml.Linq namespace.
// The LINQ query below, selects all of the lngOrderNumber and strText elements
// into an enumerable anonymous type called orders.
XDocument doc = XDocument.Parse(sr.ReadToEnd());
var orders = from a in doc.Descendants("Fields").Descendants("Field")
        select new
                   {
                       OrderNumber = a.Element("lngOrderNumber").Value,
                       Text = a.Element("strText").Value
                   };
// Iterate over the enumerable collection
foreach(var order in orders)
{
    System.Diagnostics.Debug.WriteLine("Order Number: " + order.OrderNumber);
    System.Diagnostics.Debug.WriteLine("Text: " + order.Text);
}

If this has answered your question, please click on "Mark as Answer" on this post.

Thanks,
Page Brooks, MCSD, MCAD
PageBrooks.com | RSS Feed

pbrooks

Joined on 03-23-2006
Florence, SC
Posts 116
05-09-2008 3:33 AM
Re: Upgrading from SL1.1 to SL2.0

Hi,

iam not able to read the node value,

my xml is

- <string xmlns="http://tempuri.org/">
- <NewDataSet>
- <ExposureOverall>
  <lBandId>1</lBandId>
  <lExposureId>8681831</lExposureId>
  <LimitCategory>Overall</LimitCategory>
  <TimBand>Overall</TimBand>
  <Limit>1000000</Limit>
  <Availability>1000000</Availability>
  <MTM_x0020__x0028_Replacement_x0029_>0</MTM_x0020__x0028_Replacement_x0029_>
  <Accruals>0</Accruals>
  <ArAp>0</ArAp>
  <FAR>0</FAR>
  <lLimitCategoryID>1</lLimitCategoryID>
  <lLimitCategoryTimeBandId>1</lLimitCategoryTimeBandId>
  <Total>0</Total>
  <Deals>0</Deals>
  <nDisplayOrder>1</nDisplayOrder>
  <DealsTimeBand>1</DealsTimeBand>
  </ExposureOverall>
  </NewDataSet>
  </string>
 
 
i have written like the below
XDocument xmlInput = XDocument.Parse(xmlContent);

var InputValues = from exposureOverall in xmlInput.Descendants("NewDataSet").Descendants("ExposureOverall")

select new

{

Ava = exposureOverall.Element(
"Availability").Value

};

 

iam not getting the 'InputValues'

 

Can any one help?????????????

How to get????????????

 

Thanks & Regards

Deepika

 

 
deepikaFO

Joined on 04-25-2008
Posts 7