本文介绍了在Siverlight中针对XSD验证XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Silverlight中验证我的XML文件


XSD。


我没有看到很多关于它的例子。我想使用XDocument.Validate,但它似乎在Silverlight中不可用


我的XDocument是:xDocDeliveryResponse


我的XSD是我的项目中包含的文件:DeliveryResponse.xsd


这是我的代码:



'p>


Silverlight的
空隙delmediator_DelToExternalServiceCompleted(对象发件人,svcMediator.PostToExternalServiceCompletedEventArgs E)
{
TimeStampResponse = DateTime.Now .ToString(" yyyyMMdd HH:mm:ss",System.Globalization.CultureInfo.InvariantCulture); //必须格式为:yyyymmdd hh:mm:ss(军事时间)

if(e.Error == null)
{
txtBlockStatus.Text =" Delivery确认已收到";


//这需要修改:
xDocDeliveryResponse = XDocument.Parse(e.Result);
//根据架构验证交货响应:






//这需要修改(对于多个收件人和USER_CC:

txtDeliveryResponse.Text = xDocDeliveryResponse.ToString();

SaveISO(xDocDeliveryResponse,IsoDeliveryResponse);

列表与LT; DeliveryResponse> ; deliveryresponselist =(从xDocDeliveryResponse.Elements XML(" TELEMESSAGE")元素("。TELEMESSAGE_CONTENT")元素("。MESSAGE_STATUS")元素("。RECIPIENT_STATUS")元素(" DEVICE")
选择新的DeliveryResponse()
{
Device_Type = xml.Element(" TYPE")。值,
//删除由Sprint的响应中返回的破折号,所以键字段可以连接:
Device_Value = stripnonnumeric(xml.Element(QUOT; VALUE")值。),
Message_Status = xml.Element (QUOT; STATUS")值,
Message_Status_Description = xml.Element。(QUOT;说明")值,
STATUS_TIME = xml.Element。(QUOT; STATUS_DATE")。价值
MESSAGE_ID = messageID,
Message_Key = messageKey
}
).ToList();

txtBlockStatus.Text =" Delivery Confirmation Pending ..." ;;
//获取CStatus的总和(确定程序何时完成)。
DeliveryResponseSum = deliveryresponselist.Sum(o => o.DeliveryResponseValue);
}

其他
{
var x = e.Error;
}

//确保适当的错误捕获。
//将数据写入数据库:
//仅当消息关闭,或者应用程序在完成之前意外关闭或用户关闭时:
WriteToAuditDeliveryTable();
txtBlockStatus.Text ="交付确认写入数据库";
}







John

解决方案


I'd like to validate my XML file against

an XSD in Silverlight.

I'm not seeing many examples out there on it. I'd like to use XDocument.Validate, but it doesn't seem to be available within Silverlight

my XDocument is: xDocDeliveryResponse

my XSD is a file contained in my project called: DeliveryResponse.xsd

Here is my code:

Silverlight
void delmediator_DelToExternalServiceCompleted(object sender, svcMediator.PostToExternalServiceCompletedEventArgs e)
        {
            TimeStampResponse = DateTime.Now.ToString("yyyyMMdd HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture); // Must be in format: yyyymmdd hh:mm:ss (Military Time)

            if (e.Error == null)
            {
                txtBlockStatus.Text = "Delivery Confirmation Received";


                //This needs to be modified:
                xDocDeliveryResponse = XDocument.Parse(e.Result);
                //Validate the Delivery Response against the Schema:






                //This Needs to be Modified (For Multiple Recipients and USER_CC:

                txtDeliveryResponse.Text = xDocDeliveryResponse.ToString();

                SaveISO(xDocDeliveryResponse, IsoDeliveryResponse);

                List<DeliveryResponse> deliveryresponselist = (from xml in xDocDeliveryResponse.Elements("TELEMESSAGE").Elements("TELEMESSAGE_CONTENT").Elements("MESSAGE_STATUS").Elements("RECIPIENT_STATUS").Elements("DEVICE")
                                                               select new DeliveryResponse()
                                                               {
                                                                   Device_Type = xml.Element("TYPE").Value,
                                                                   //Remove the dashes that are returned by Sprint response, so the Key Field can be joined:
                                                                   Device_Value = stripnonnumeric(xml.Element("VALUE").Value),
                                                                   Message_Status = xml.Element("STATUS").Value,
                                                                   Message_Status_Description = xml.Element("DESCRIPTION").Value,
                                                                   Status_Time = xml.Element("STATUS_DATE").Value,
                                                                   Message_Id = messageID,
                                                                   Message_Key = messageKey
                                                               }
                                                               ).ToList();

                txtBlockStatus.Text = "Delivery Confirmation Pending...";
                //Get the Sum of the CStatus (To ascertain when procedure is completed).
                DeliveryResponseSum = deliveryresponselist.Sum(o => o.DeliveryResponseValue);
            }

            else
            {
                var x = e.Error;
            }

            //ensure appropriate Error Trapping.
            //Write Data to Database:
            //Only when Message is closed, or if application shuts down unexpectedly or closed by user prior to being completed:
            WriteToAuditDeliveryTable();
            txtBlockStatus.Text = "Delivery Confirmation Written To Database";
        }



John

解决方案


这篇关于在Siverlight中针对XSD验证XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 17:51