Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# VS 2008 3.5 XML/Webservice error

C# VS 2008 3.5 XML/Webservice error

Scheduled Pinned Locked Moved C#
csharphelpvisual-studioxmlquestion
13 Posts 3 Posters 14 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • realJSOPR realJSOP

    The most glaring thing is the hyphens before the root tags. Further, your code should probably look more like this:

    XElement element = Results.Elements("NewDataSet").Element("Table");
    string city = element.Element("CITY").Value;
    string state = element.Element("STATE").Value;
    ... blah blah

    .45 ACP - because shooting twice is just silly
    -----
    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
    -----
    "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

    W Offline
    W Offline
    Wheels012
    wrote on last edited by
    #3

    The problem I am having now is that th eLoad is looking for a physical XML file on my computer, but it is being called from a Web Service.

    XDocument doc = XDocument.Load(ws.GetInfoByZIP(txtZip.Text).ToString());

    private void btnZipWS_Click(object sender, EventArgs e)
    {

            Bank.net.webservicex.www.USZip ws = new Bank.net.webservicex.www.USZip();
    
           
            XDocument doc = XDocument.Load(ws.GetInfoByZIP(txtZip.Text).ToString());
                     XElement element = Results.Elements("NewDataSet").Element("Table"); 
            string city = element.Element("CITY").Value; 
            string state = element.Element("STATE").Value;
    

    WHEELS

    realJSOPR 1 Reply Last reply
    0
    • W Wheels012

      The problem I am having now is that th eLoad is looking for a physical XML file on my computer, but it is being called from a Web Service.

      XDocument doc = XDocument.Load(ws.GetInfoByZIP(txtZip.Text).ToString());

      private void btnZipWS_Click(object sender, EventArgs e)
      {

              Bank.net.webservicex.www.USZip ws = new Bank.net.webservicex.www.USZip();
      
             
              XDocument doc = XDocument.Load(ws.GetInfoByZIP(txtZip.Text).ToString());
                       XElement element = Results.Elements("NewDataSet").Element("Table"); 
              string city = element.Element("CITY").Value; 
              string state = element.Element("STATE").Value;
      

      WHEELS

      realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote on last edited by
      #4

      Since you're getting an XML string back from the web service, you want to use this:

      XDocument doc = XDocument.Parse(textZip.Text);

      .45 ACP - because shooting twice is just silly
      -----
      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

      W 1 Reply Last reply
      0
      • realJSOPR realJSOP

        Since you're getting an XML string back from the web service, you want to use this:

        XDocument doc = XDocument.Parse(textZip.Text);

        .45 ACP - because shooting twice is just silly
        -----
        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
        -----
        "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

        W Offline
        W Offline
        Wheels012
        wrote on last edited by
        #5

        Hi John. I am semi-following. I wouldn't be parsing the txtZip.Text. That is a textbox on the form and the data is being passed to the WS call.

        XDocument doc = XDocument.Parse(ws.GetInfoByZIP(txtZip.Text).ToString());

        When I use this, I am getting this error: Data at the root level is invalid. Line 1, position 1. WHEELS

        realJSOPR 1 Reply Last reply
        0
        • W Wheels012

          Hi John. I am semi-following. I wouldn't be parsing the txtZip.Text. That is a textbox on the form and the data is being passed to the WS call.

          XDocument doc = XDocument.Parse(ws.GetInfoByZIP(txtZip.Text).ToString());

          When I use this, I am getting this error: Data at the root level is invalid. Line 1, position 1. WHEELS

          realJSOPR Offline
          realJSOPR Offline
          realJSOP
          wrote on last edited by
          #6

          Like I said in my original response - you have hyphens preceding the two root-most elements. That makes your XML invalid.

          .45 ACP - because shooting twice is just silly
          -----
          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

          W 1 Reply Last reply
          0
          • realJSOPR realJSOP

            Like I said in my original response - you have hyphens preceding the two root-most elements. That makes your XML invalid.

            .45 ACP - because shooting twice is just silly
            -----
            "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
            -----
            "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

            W Offline
            W Offline
            Wheels012
            wrote on last edited by
            #7

            Very new to XML. What do I do to compensate for the - s? WHEELS

            L 1 Reply Last reply
            0
            • W Wheels012

              Very new to XML. What do I do to compensate for the - s? WHEELS

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #8

              it is not valid XML as long as those hyphens are there. Eradicate them. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              Prolific encyclopedia fixture proof-reader browser patron addict?
              We all depend on the beast below.


              W 1 Reply Last reply
              0
              • L Luc Pattyn

                it is not valid XML as long as those hyphens are there. Eradicate them. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                Prolific encyclopedia fixture proof-reader browser patron addict?
                We all depend on the beast below.


                W Offline
                W Offline
                Wheels012
                wrote on last edited by
                #9

                Thank you Luc.

                realJSOPR 1 Reply Last reply
                0
                • W Wheels012

                  Thank you Luc.

                  realJSOPR Offline
                  realJSOPR Offline
                  realJSOP
                  wrote on last edited by
                  #10

                  Isn't that what I told you, too?

                  .45 ACP - because shooting twice is just silly
                  -----
                  "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                  -----
                  "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                  W 1 Reply Last reply
                  0
                  • realJSOPR realJSOP

                    Isn't that what I told you, too?

                    .45 ACP - because shooting twice is just silly
                    -----
                    "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                    -----
                    "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                    W Offline
                    W Offline
                    Wheels012
                    wrote on last edited by
                    #11

                    Hi John. I believe you did. Having a very challenging time with this XML/WebService, and didn't expect to enough these hypens. Thanks again. WHEELS

                    realJSOPR 1 Reply Last reply
                    0
                    • W Wheels012

                      Hi John. I believe you did. Having a very challenging time with this XML/WebService, and didn't expect to enough these hypens. Thanks again. WHEELS

                      realJSOPR Offline
                      realJSOPR Offline
                      realJSOP
                      wrote on last edited by
                      #12

                      I'm working on a project as we speak that's getting XML from a SQL database stored procedure via a web service, and I'm not getting any hyphens. Can I assume you solved your problem?

                      .45 ACP - because shooting twice is just silly
                      -----
                      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                      -----
                      "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                      W 1 Reply Last reply
                      0
                      • realJSOPR realJSOP

                        I'm working on a project as we speak that's getting XML from a SQL database stored procedure via a web service, and I'm not getting any hyphens. Can I assume you solved your problem?

                        .45 ACP - because shooting twice is just silly
                        -----
                        "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                        -----
                        "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                        W Offline
                        W Offline
                        Wheels012
                        wrote on last edited by
                        #13

                        Found a work around, although not as elegant as I would like:

                        Bank.net.webservicex.www.USZip ws = new Bank.net.webservicex.www.USZip();

                                XmlNode cityNode = ws.GetInfoByZIP(txtZip.Text);
                        
                                string cityName = "UNKNOWN";
                                string stateName = "UNKNOWN";
                                foreach (XmlNode node in cityNode)
                                {
                                    foreach (XmlElement elem in node)
                                    {
                                        if (elem != null && elem.Name.Equals("CITY"))
                                        {
                                            cityName = elem.FirstChild.InnerText;
                                        }
                                        if (elem != null && elem.Name.Equals("STATE"))
                                        {
                                            stateName = elem.FirstChild.InnerText;
                                        }
                                    }
                                }
                                txtCity.Text = cityName;
                                txtState.Text = stateName; 
                        

                        WHEELS

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups