Click here to Skip to main content
16,016,623 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I am trying to load an XML into C#. There needs to be a "using ?????" for this to work. How do I do this.

C#
      xmldoc1 = XDocument.Load(Server.MapPath("~/xml/VSOP87 - 1 Data.xml"));
elements1 = from data in xmldoc1.Descendants("Table")
            select new
            {
                A1mer = Convert.ToDouble(data.Element("A1mer").Value),
                B1mer = Convert.ToDouble(data.Element("B1mer").Value),
                C1mer = Convert.ToDouble(data.Element("C1mer").Value),
                A1ven = Convert.ToDouble(data.Element("A1ven").Value),
                B1ven = Convert.ToDouble(data.Element("B1ven").Value),
                C1ven = Convert.ToDouble(data.Element("C1ven").Value),
                A1ear = Convert.ToDouble(data.Element("A1ear").Value),
                B1ear = Convert.ToDouble(data.Element("B1ear").Value),
                C1ear = Convert.ToDouble(data.Element("C1ear").Value),
                A1mar = Convert.ToDouble(data.Element("A1mar").Value),
                B1mar = Convert.ToDouble(data.Element("B1mar").Value),
                C1mar = Convert.ToDouble(data.Element("C1mar").Value),
                A1jup = Convert.ToDouble(data.Element("A1jup").Value),
                B1jup = Convert.ToDouble(data.Element("B1jup").Value),
                C1jup = Convert.ToDouble(data.Element("C1jup").Value),
                A1sat = Convert.ToDouble(data.Element("A1sat").Value),
                B1sat = Convert.ToDouble(data.Element("B3sat").Value),
                C1sat = Convert.ToDouble(data.Element("C1sat").Value),
                A1ura = Convert.ToDouble(data.Element("A1ura").Value),
                B1ura = Convert.ToDouble(data.Element("B1ura").Value),
                C1ura = Convert.ToDouble(data.Element("C1ura").Value),
                A1nep = Convert.ToDouble(data.Element("A1nep").Value),
                B1nep = Convert.ToDouble(data.Element("B1nep").Value),
                C1nep = Convert.ToDouble(data.Element("C1nep").Value),
                A1emb = Convert.ToDouble(data.Element("A1emb").Value),
                B1emb = Convert.ToDouble(data.Element("B1emb").Value),
                C1emb = Convert.ToDouble(data.Element("C1emb").Value)
            };

foreach (var element in elements1){
    ov(1) = ov(1) + 1;
    vpi(3, 1, 1, ov(1)) = element.A1mer;
    vpi(3, 2, 1, ov(1)) = element.B3mer;
    vpi(3, 3, 1, ov(1)) = element.C1mer;
    vpi(3, 1, 2, ov(1)) = element.A1ven;
    vpi(3, 2, 2, ov(1)) = element.B1ven;
    vpi(3, 3, 2, ov(1)) = element.C1ven;
    vpi(3, 1, 3, ov(1)) = element.A1ear;
    vpi(3, 2, 3, ov(1)) = element.B1ear;
    vpi(3, 3, 3, ov(1)) = element.C1ear;
    vpi(3, 1, 4, ov(1)) = element.A1mar;
    vpi(3, 2, 4, ov(1)) = element.B1mar;
    vpi(3, 3, 4, ov(1)) = element.C1mar;
    vpi(3, 1, 5, ov(1)) = element.A1jup;
    vpi(3, 2, 5, ov(3)) = element.B1jup;
    vpi(3, 3, 5, ov(1)) = element.C1jup;
    vpi(3, 1, 6, ov(1)) = element.A1sat;
    vpi(3, 2, 6, ov(1)) = element.B1sat;
    vpi(3, 3, 6, ov(1)) = element.C1sat;
    vpi(3, 1, 7, ov(1)) = element.A1ura;
    vpi(3, 2, 7, ov(1)) = element.B1ura;
    vpi(3, 1, 8, ov(1)) = element.A1nep;
    vpi(3, 2, 8, ov(1)) = element.B1nep;
    vpi(3, 3, 8, ov(1)) = element.C1nep;
    vpi(3, 1, 9, ov(1)) = element.A1emb;
    vpi(3, 2, 9, ov(1)) = element.B1emb;
    vpi(3, 3, 9, ov(1)) = element.C1emb;
}


What I have tried:

Need to enter a "using ???.xml".
Posted
Updated 7-Jan-23 20:05pm

1 solution

Thirty seconds with Google and the Microsoft documentation would have told you that XDocument is part of the System.Xml.Linq namespace: XDocument Class (System.Xml.Linq) | Microsoft Learn[^]

So ... is
C#
using System.Xml.Linq;
what you were looking for?
 
Share this answer
 
Comments
John Ertle Jr 8-Jan-23 13:42pm    
That still did not work.
Richard Deeming 9-Jan-23 8:20am    
Aside from the fact that you're trying to assign values to a function - vpi(3, 1, 1, ov(1)) = element.A1mer; is not valid C#, and will result in a CS0131 compiler error[^] - you haven't explained what the problem is.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900