小编psu*_*003的帖子

根元素缺失

我正在从xxx URl读取xml,但由于缺少Root元素,我收到错误.

我读取xml响应的代码如下:

  XmlDocument doc = new XmlDocument();
  doc.Load("URL from which i am reading xml");
  XmlNodeList nodes = doc.GetElementsByTagName("Product");
  XmlNode node = null;
  foreach (XmlNode n in nodes)
   {
   }
Run Code Online (Sandbox Code Playgroud)

并且xml响应如下:

<All_Products>
   <Product>
  <ProductCode>GFT</ProductCode>
  <ProductName>Gift Certificate</ProductName>
  <ProductDescriptionShort>Give the perfect gift. </ProductDescriptionShort>
  <ProductDescription>Give the perfect gift.</ProductDescription>
  <ProductNameShort>Gift Certificate</ProductNameShort> 
  <FreeShippingItem>Y</FreeShippingItem>
  <ProductPrice>55.0000</ProductPrice>
  <TaxableProduct>Y</TaxableProduct>
   </Product>    
 </All_Products>
Run Code Online (Sandbox Code Playgroud)

你能告诉我哪里出错了.

c# xml asp.net

14
推荐指数
3
解决办法
8万
查看次数

如何在TreeView中混合数据绑定和静态级别?

我有一组Database对象,每个对象都包含Schema对象和User对象的集合.我想将它们绑定到TreeView,但在层次结构中添加其他静态级别,以便生成的TreeView看起来或多或少像这样:

<TreeView>
    <TreeViewItem Header="All the databases:">
        <TreeViewItem Header="Db1">
            <TreeViewItem Header="Here's all the schemas:">
                <TreeViewItem Header="Schema1"/>
                <TreeViewItem Header="Schema2"/>
            </TreeViewItem>
            <TreeViewItem Header="Here's all the users:">
                <TreeViewItem Header="User1"/>
                <TreeViewItem Header="User2"/>
            </TreeViewItem>
        </TreeViewItem>
        <TreeViewItem Header="Db2">
            <TreeViewItem Header="Here's all the schemas:">
                <TreeViewItem Header="Schema1"/>
                <TreeViewItem Header="Schema2"/>
            </TreeViewItem>
            <TreeViewItem Header="Here's all the users:">
                <TreeViewItem Header="User1"/>
                <TreeViewItem Header="User2"/>
            </TreeViewItem>
        </TreeViewItem>
    </TreeViewItem>
</TreeView>
Run Code Online (Sandbox Code Playgroud)

通过使用以下模板,我能够非常接近我想要的东西:

<Window.Resources>
    <HierarchicalDataTemplate DataType="{x:Type smo:Database}">
        <TreeViewItem Header="{Binding Path=Name}">
            <TreeViewItem Header="Here's all the schemas:" ItemsSource="{Binding Path=Schemas}"/>
            <TreeViewItem Header="Here's all the users:" …
Run Code Online (Sandbox Code Playgroud)

data-binding wpf treeview hierarchicaldatatemplate

12
推荐指数
1
解决办法
3527
查看次数

解决方案打开时,"Visual Studio 2012已停止工作"

当我打开Visual Studio时,一切都很好,但是当我打开任何解决方案时,它会出现错误:

Visual Studio 2012 for Windows桌面已停止工作.

我现在开始变得非常沮丧,任何人都可以帮忙吗?我不想失去我的所有工作.

我昨天格式化了我的电脑,重新安装了我的所有软件并整天使用Visual Studio,这很好.当我关闭计算机时,它更新到最新版本的Windows更新,然后今天早上我打开它时完成更新,现在我再也无法打开我的任何解决方案.

visual-studio visual-studio-2012

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

监听音频线路

我需要监控我的音频线路输入在Linux中,并在音频播放时,声音必须被记录并保存到一个文件中.与运动如何监控视频输入类似.

是否有可能用bash做到这一点?类似的东西:

#!/bin/bash

# audio device
device=/dev/audio-line-in

# below this threshold audio will not be recorded.
noise_threshold=10

# folder where recordings are stored
storage_folder=~/recordings

# run indefenitly, until Ctrl-C is pressed
while true; do
   # noise_level() represents a function to determine
   # the noise level from device
   if noise_level( $device ) > $noise_threshold; then
     # stream from device to file, can be encoded to mp3 later.
     cat $device > $storage_folder/$(date +%FT%T).raw         
   fi;
done;
Run Code Online (Sandbox Code Playgroud)

编辑:我想从这个程序中获得的流程是

 a. when …
Run Code Online (Sandbox Code Playgroud)

linux audio bash audio-recording

11
推荐指数
1
解决办法
6459
查看次数

"java.net.MalformedURLException:未找到协议"读取到html文件

我收到了一个错误: java.net.MalformedURLException: Protocol not found

我想在网上阅读HTML文件

mainfest :::::   uses-permission android:name="android.permission.INTERNET"

uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" 

import com.doviz.R.id;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {

public String inputLine;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    String myUri = "";
    myUri = "www.tcmb.gov.tr/kurlar/today.html";


    Toast.makeText( this, "step-1 " , Toast.LENGTH_LONG).show();
    try{
            Toast.makeText( this, "step -2" , Toast.LENGTH_LONG).show();
            myUri = "www.tcmb.gov.tr/kurlar/today.html";

        URL url = new URL(myUri);

        Toast.makeText( this, "step-3" , Toast.LENGTH_LONG).show();
            final InputStream is =url.openStream();
            Toast.makeText( this, …
Run Code Online (Sandbox Code Playgroud)

java

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

检查String是否可以在C#中转换为给定类型

我必须验证用户输入数据并确保字符串值可以转换为在运行时指定的类型.我不一定需要进行实际转换,只需测试以确保输入值有效.我还没有找到可以执行此类评估的内置类或方法,但如果我遗漏了一个,请告诉我.我正在使用C#4.0,如果有任何特定于版本的解决方案可用.

该方法只需要处理"标准"类型(内置值数据类型加上String).我需要评估的唯一自定义类型是库中定义的特定枚举类型.

我有2个解决方案,我正在权衡,但两者都不是完美的,所以我希望有第三个选项(或者我错过的框架内置的东西).我非常倾向于解决方案#2,因为在解决方案#1中使用try-catch似乎是错误的.

解决方案1:Convert.ChangeType()使用try/catch

public Boolean CheckType(String value, Type type)
{
    try
    {
        var obj = Convert.ChangeType(value, type);
        return true;
    }
    catch(InvalidCastException)
    {
        return false;
    }
    catch(FormatException)
    {
        return false;
    }
    catch(OverflowException)
    {
        return false;
    }
    catch(ArgumentNullException)
    {
        return false;
    }
}
Run Code Online (Sandbox Code Playgroud)

解决方案2 if/else链接Type Check和TryParse

public Boolean CheckType(String value, Type type)
{
    if (type == typeof(String))
    {
        return true;
    }
    else if (type == typeof(Boolean))
    {
        Boolean b;
        return Boolean.TryParse(value, out b); 
    }
    else if (type == …
Run Code Online (Sandbox Code Playgroud)

c# type-conversion

9
推荐指数
3
解决办法
2万
查看次数

如何使用C#解析XSD以从<xsd:simpleType>元素获取信息?

我有一个具有多种复杂类型和简单类型的XSD(文件的一部分如下所示).我需要解析此文档以从复杂类型中引用的每个简单类型中获取maxLength.任何人都可以请求如何实现这一点?我需要以通用的方式实现它,所以如果我查询"Setup_Type",它应该给出以下输出.谢谢!

NewSetup/Amount = 12(元素标签的名称属性由"/"和嵌套的simpleType中的maxLength分隔)

NewSetup/Name = 50

<xsd:complexType name="Setup_Type">
  <xsd:sequence>
    <xsd:element name="NewSetup" type="NewSetup_Type" minOccurs="1" maxOccurs="1" />
  </xsd:sequence>
</xsd:complexType>

<xsd:complexType name="NewSetup_Type">
  <xsd:sequence>
    <xsd:element name="Amount" type="Amount_Type"  minOccurs="1" maxOccurs="1" />
    <xsd:element name="Name" type="Name_Type"  minOccurs="1" maxOccurs="1" />
  </xsd:sequence>
</xsd:complexType>

<xsd:simpleType name="Amount_Type">
  <xsd:annotation>
    <xsd:documentation>Amount</xsd:documentation>
  </xsd:annotation>
  <xsd:restriction base="xsd:string">
    <xsd:maxLength value="12" />
  </xsd:restriction>
</xsd:simpleType>

<xsd:simpleType name="Name_Type">
  <xsd:annotation>
    <xsd:documentation>Name</xsd:documentation>
  </xsd:annotation>
  <xsd:restriction base="xsd:string">
    <xsd:maxLength value="50" />
  </xsd:restriction>
</xsd:simpleType>
Run Code Online (Sandbox Code Playgroud)

c# xsd c#-4.0

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

如何在HierarchicalDataTemplate的DataType属性中引用泛型类型?

我有一个类,MyClass<MyObject>并希望将其设置为HierarchicalDataTemplate的DataType.

XAML中的语法是什么?(我知道如何设置命名空间,我只需要语法

<HierarchicalDataTemplate DataType="{X:Type .....
Run Code Online (Sandbox Code Playgroud)

.net wpf xaml hierarchicaldatatemplate

7
推荐指数
2
解决办法
6124
查看次数

XElement的XML模式验证

我正在处理多个XElement对象,为我的库中的多个对象提供一些用户指定的数据.我试图避免指定整个XML文件的结构,因为只要所需的特定元素正确构造,库就不应该关心整个XML的样子.

为此,我有3个单独的XSD文件,为XElements我的3个类的每个需求定义模式,但是我遇到了一些问题,根据模式验证了XElement.没有解决方法似乎没有办法做到这一点.

在MSDN页面中,XElement.Validate()扩展方法似乎适合于重新验证较大文件的子元素.这个XmlSchemaObject论点引起了我的问题,因为我无法假设它会出现在任何一个问题中XElements.我想我可以解决这个问题,抓住XmlSchemaElementXmlSchemaSet的传递作为XmlSchemaObject参数,但由于XmlSchemaSet已经定义了一切,所以必须这样做似乎很奇怪.

XElement没有首先验证整个模式的情况下,是否有更好的选项来验证模式XDocument

或者我应该让业务层处理应用程序中的模式验证并让库假设XElement正确形成(我考虑了这个选项,但作为个人偏好更喜欢避免抛出异常而宁愿让调用方法知道在XElement通过返回参数无效).

c# xml xsd linq-to-xml

7
推荐指数
1
解决办法
5046
查看次数

元组<T1,T2>和KeyValuePair <T1,T2>之间的转换

KeyValuePair<T1, T2>和之间是否有内置的转换或转换Tuple<T1, T2>

我知道这将是一个简单的扩展方法:

public static KeyValuePair<T1, T2> ToPair<T1, T2>(this Tuple<T1, T2> source)
{
    return new KeyValuePair<T1, T2>(source.Item1, source.Item2);
}

public static Tuple<T1, T2> ToTuple<T1, T2>(this KeyValuePair<T1, T2> source)
{
    return Tuple.Create(source.Key, source.Value);
}
Run Code Online (Sandbox Code Playgroud)

但是因为对象可以用于类似的目的(特别是因为KeyValuePair<>它经常被用来代替2元素,Tuple<>直到它添加到C#4.0),我想知道这样的转换器是否已经内置到框架中了?

我问的原因是我正在使用一个较旧的库(针对.NET 3.5),该库KeyValuePair<>在很多地方都使用了元组可能更合适,我想Tuple<>在新代码中使用.所以我想弄清楚我是否可以将kvp这些方法的返回值转换或转换为Tuple或者如果我需要定义自己的转换(或更改旧代码).

c#-4.0

7
推荐指数
1
解决办法
1085
查看次数