0

Tengo una aplicacion la cual llama un servicio web. Para esto estoy usando LINQ.

Lo que deseo hacer esque el valor de 'Caption' venga desde un archivo XML en el cual paso como parametro.

Al hacer el debug veo que el parametro pasa bien, pero me devuelve null.

Que estoy haciendo mal?

Aqui esta mi codigo:

Este es el archivo XML:

<root>   
     <dataSourceCaption>Users</dataSourceCaption>
</root>

Este es el codigo:

int count = xml.GetElementsByTagName("dataSourceCaption").Count;

for (int i = 0; i < count; ++i)
{
    dataSourceCaption.Add(xml.GetElementsByTagName("dataSourceCaption")[i].InnerText);
}

var ds = etDataSourceMappingTable();
foreach (DataTable dst in ds.Tables)
{
    foreach (DataRow dr in dst.Rows)
    {
        //var DataSourceId = dr["SourceID"].ToString();
        var DataSourceId = ds.Tables["Table"]
            //.Select("Caption = 'TeachersTests'") // Find rows with Caption
        .Select("Caption = '" + dataSourceCaption.ToString() + "'") // Find rows with Caption
        .Select(r => r["SourceID"])       // Project to the value of SourceId
        .Where(s => s != DBNull.Value)    // Filter DBNull (might occur when the SourceID cell is missing
        .Select(s => s.ToString())       // Project to string value
        .FirstOrDefault();

        SourceID = DataSourceId;
    }
}
return SourceID;

Este es el schema del servicio web que estoy llamando:

  <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
       <xs:element name="NewDataSet" msdata:IsDataSet="true" msdata:UseCurrentLocale="true">
          <xs:complexType>
             <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element name="Table">
                   <xs:complexType>
                      <xs:sequence>
                         <xs:element name="SourceID" type="xs:string" minOccurs="0"/>
                         <xs:element name="Caption" type="xs:string" minOccurs="0"/>
                      </xs:sequence>
                   </xs:complexType>
                </xs:element>
             </xs:choice>
          </xs:complexType>
       </xs:element>
    </xs:schema>

1 respuesta 1

0

podrías hacer algo como esto:

XmlDocument xDoc = new XmlDocument();
                xDoc.Load(@"\..\..\ComprobantePagos.xml");
                XmlNodeList xTipoComprobante = xDoc.GetElementsByTagName("DocumentElement");
                XmlNodeList xLista = ((XmlElement)xTipoComprobante[0]).GetElementsByTagName("TipoComprobante");

                foreach (XmlElement nodo in xLista)
                {
                    int i = 0;
                    XmlNodeList xNumero = nodo.GetElementsByTagName("Numero");
                    XmlNodeList xDescripcion = nodo.GetElementsByTagName("Descripcion");

                    TipoComprobante entity = new TipoComprobante
                    {
                        Numero = xNumero[i].InnerText,
                        Descripcion = xDescripcion[i++].InnerText
                    };

Es un código de ejemplo, tendrías que adaparlo a tus necesicades.

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.