小编naf*_*fie的帖子

使用XmlDocument从带或不带命名空间的xml文件中读取

我有一些代码使用XmlDocument从带有命名空间的xml文件读取.我的挑战是我有文件的命名空间我现在正在阅读硬编码并且我将它传递给XmlNamespaceManager.I希望我的方法是从任何类型的xml文件读取.如果它有一个命名空间,那么使用命名空间管理器来读取元素而无需对命名空间进行硬编码.如果文件没有命名空间,那么请继续解析它.我就是这样做的.

xmldoc = new XmlDocument ();
xmldoc.Load (fileLocation);


XmlNamespaceManager nameSpaceManager = new XmlNamespaceManager(xmldoc.NameTable);

nameSpaceManager.AddNamespace ("ns","http://schemas.sample.data.org/2005");

XmlNodeList nodeList = xmldoc.SelectNodes("/ns:Demo/ns:Items",  nameSpaceManager);
if (nodeList != null) 
{
    foreach (XmlNode childNode in nodeList) 
    {
        string first = childNode.SelectSingleNode ("ns:First", nameSpaceManager).InnerText;
        string second= childNode.SelectSingleNode ("ns:Second", nameSpaceManager).InnerText;
        string third = childNode.SelectSingleNode ("ns:Third", nameSpaceManager).InnerText;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是我正在使用的示例xml文件

<Demo xmlns:i="http://www.justasample.com" xmlns="http://schemas.sample.data.org/2005">
 <Items>

  <First>first</First>
  <Second>second</Second>
  <Third>third</Third>

  </Items>

</Demo>
Run Code Online (Sandbox Code Playgroud)

c# xml namespaces

8
推荐指数
1
解决办法
2万
查看次数

通过 SendGrid c# 发送电子邮件附件失败

我正在使用 Azure 移动服务后端,并且可以通过 SendGrid 成功发送电子邮件。但是,每次我尝试添加附件时,都会失败。我从来没有收到过电子邮件。经过一番研究,我发现我所需要的只是一条虚拟路径。我修改了路径名,但还是不行。

我似乎无法弄清楚为什么会失败。

下面是我的代码:

var client = new SendGridClient("apiKey");

var msg = new SendGridMessage()
        {
            From = new EmailAddress(sender),
            Subject = "Adherence Report",
            PlainTextContent = "Sample Content ",
            HtmlContent = "<strong>Hello, Email!</strong>"
        };
            msg.AddTo(new EmailAddress(receipient, null));
            msg.AddAttachment(@"~\sample\adherence.csv", "Testing", null, null, null);

        var response = await client.SendEmailAsync(msg);
Run Code Online (Sandbox Code Playgroud)

c# sendgrid

4
推荐指数
1
解决办法
7597
查看次数

实现android内容提供程序的查询方法,使用多个表

我有三个表,并希望使用内容提供商来管理它们.下面是我的内容提供商提供的代码:

private static final UriMatcher sURIMatcher = new UriMatcher(
        UriMatcher.NO_MATCH);
static {
    sURIMatcher.addURI(AUTHORITY, METER_PATH, all_meters);
    sURIMatcher.addURI(AUTHORITY, METER_PATH + "/#", single_meter);

    sURIMatcher.addURI(AUTHORITY, CUSTOMERS_PATH, all_customers);
    sURIMatcher.addURI(AUTHORITY, CUSTOMERS_PATH + "/#", single_customer);

    sURIMatcher.addURI(AUTHORITY, BILL_PATH, all_bills);
    sURIMatcher.addURI(AUTHORITY, BILL_PATH + "/#", single_bill);

}

@Override
public Cursor query(Uri uri, String[] projection, String selection,
        String[] selectionArgs, String sortOrder) {

    SQLiteDatabase db = database.getWritableDatabase();

    // Using SQLiteQueryBuilder instead of query() method
    SQLiteQueryBuilder queryBuilder = new SQLiteQueryBuilder();

queryBuilder
            .setTables(MeterTableDetails.TABLE_METERS
                    + " as meters "
                    + " INNER JOIN "
                    + …
Run Code Online (Sandbox Code Playgroud)

android android-contentprovider android-sqlite

3
推荐指数
1
解决办法
6089
查看次数

在android中重复出现模糊列名_id sqlite错误

我已经尝试根据我在这个网站上找到的建议编辑我的代码,但似乎没有任何工作..我仍然得到以下logcat错误:

03-24 11:44:27.037: E/AndroidRuntime(1809): Caused by: android.database.sqlite.SQLiteException: 
ambiguous column name: _id (code 1): , while compiling: 
CREATE VIEW customerView AS SELECT _id AS _id,   fName, lName, customerMeterId, customerMeterNumber,   customerPlotNumber, _id FROM customers AS customers  
INNER JOIN meters AS meters ON customerMeterId =_id
Run Code Online (Sandbox Code Playgroud)

上面在logcat中引用的类:

public class ViewCustomers {

public static final String TABLE_CUSTOMER_VIEW = "customerView";

public static final String CUSTOMER_VIEW_ID = CustomerTableDetails.KEY_CUSTOMER_ID;
public static final String CUSTOMER_VIEW_FIRSTNAME = CustomerTableDetails.KEY_FIRST_NAME;
public static final String CUSTOMER_VIEW_LASTNAME = CustomerTableDetails.KEY_LAST_NAME;
public static final String CUSTOMER_VIEW_METER …
Run Code Online (Sandbox Code Playgroud)

sqlite android

2
推荐指数
1
解决办法
4912
查看次数

Azure 应用服务错误 405 - 请求无法完成。(不允许的方法)

我正在使用 Azure 应用服务 .NET 后端和 Xamarin.iOS 应用程序。我能够成功注册新用户,并且可以在数据库中查看该用户的详细信息。我有一个自定义 ApiController,它处理注册,并且我能够通过成功的 POST 调用保存详细信息。

\n\n

但是,当我尝试登录该应用程序时,出现以下错误:

\n\n
{Microsoft.WindowsAzure.MobileServices.MobileServiceInvalidOperationException: The request could not be completed.  (Method Not Allowed) \n
Run Code Online (Sandbox Code Playgroud)\n\n

下面是我的代码:

\n\n

后端成功进行 POST 调用的 RegistrationController

\n\n
[MobileAppController]\n[RoutePrefix("api/register")]\n[AllowAnonymous]\npublic class RegisterController : ApiController\n{\n\n     [HttpPost]\n    [Route("newuser")]\n    public HttpResponseMessage NewUser(RegistrationRequest request)\n    {\n        // Registration code in here\n\n    }\n\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

这就是我在客户端调用此函数的方式:

\n\n
public async Task<Result<UserProfile>> RegisterUser(RegistrationWrapper registrationrequest)\n    {\n        try\n        {\n            var registrationRequest = new JObject();\n            registrationRequest.Add("username", registrationrequest.username);\n            registrationRequest.Add("password", registrationrequest.password);\n            registrationRequest.Add("email", registrationrequest.email);\n            registrationRequest.Add("phone", registrationrequest.phone);\n            registrationRequest.Add("firstname", registrationrequest.firstname);\n            registrationRequest.Add("lastname", registrationrequest.lastname);\n\n            var result …
Run Code Online (Sandbox Code Playgroud)

azure xamarin.ios azure-web-app-service

2
推荐指数
1
解决办法
5901
查看次数