1

I am trying to process the following XML:

<rif:Rif xmlns:rif="rif" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" rif:numeroRif="XYZXYZXYZ">
    <rif:Nombre>Nombre</rif:Nombre>
    <rif:AgenteRetencionIVA>SI</rif:AgenteRetencionIVA>
    <rif:ContribuyenteIVA>SI</rif:ContribuyenteIVA>
    <rif:Tasa />
</rif:Rif>

An I am using the next code:

XDocument doc = XDocument.Parse(result);
var q = from item in doc.Descendants()
        let attributeType = item.Attribute("AgenteRetencionIVA").Value
        select item;

I have problems to get the attribute rif:AgenteRetencionIVA. How do I to do it?

1 Answer 1

1

Looks like tou need to specify custom namespace:

string xml = @"...";

XName nameRif = "rif";
XDocument doc = XDocument.Parse(xml);

var q = from item in doc.Descendants()
        let attributeType = item.Attribute(nameRif + "AgenteRetencionIVA")
        select item.Value;
var a = q.ToArray();
Sign up to request clarification or add additional context in comments.

2 Comments

@user2112467: Declare XName out of LINQ query and use it with each element name.
@user2112467: You're doing something wrong. Works fine for me. See recent update.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.