?
Solved

ASP.net XML getting and parsing

Posted on 2004-11-24
10
Medium Priority
?
443 Views
Last Modified: 2013-11-25
I need something to read a XML string and grab attributes from it in asp.net
The source of the XML is a local script, but the script need to be executed:
www.mysite.com/ascript.asp

As you'll notice the XML source is also classic asp, not .net so this is the only realy way i can do this.

There is also only one element per xml request, so there's no need to throw any of this into a datagrid

a sample of the XML would be something like: <element><attrib1>pie</attrib1><attrib2>chocolate</attrib2><element>

so yeah, i want attrib1 and attrib2...
0
Comment
Question by:OliWarner
  • 5
  • 4
9 Comments
 
LVL 16

Author Comment

by:OliWarner
ID: 12668017
at the moment my code looks a little like this:

            dim webC As New System.Net.WebClient()
            Dim orgn As String = ""
            Dim ispn As String = ""
            Dim ispd As String = ""
            Dim ispc As String = ""

        Try
            Dim remoteUrl as String = "http://www.thepcspy.com/tools/page.asp?ip=" + ip
                  Dim myDatabuffer As Byte() = webC.DownloadData(remoteUrl)
                  Dim download as String = Encoding.ASCII.GetString(myDataBuffer)

apart from the connection to the web-page cant be established to download it... its quite odd...
0
 
LVL 9

Assisted Solution

by:riyasjef
riyasjef earned 2000 total points
ID: 12668183
Why can't use xmlHTTP to do it....

See this

http://www.csharpfriends.com/Forums/ShowPost.aspx?PostID=27419

RJ
0
 
LVL 16

Author Comment

by:OliWarner
ID: 12669894
Dim xmlHTTP As New XMLHTTP
Dim strXML As String
xmlHTTP.open("POST", strUrl)
xmlHTTP.Send(postdata)
strXML = xmlHTTP.ResponseText()
DisplayXML(ParseXML(strXML))
ProcessData = strXML

ok, but how do i requests the elemnts from the XML?
I've no exp with XML and asp.net and i'm not looking to get too bogged down in something that I could as easily build my own parser...
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 9

Accepted Solution

by:
riyasjef earned 2000 total points
ID: 12689075
Here is a simple working example for you

<%@ Page language="c#"  %>
<%@ Import Namespace="System.Xml" %>
<script language="C#" runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
 Response.Write( ReadXML("http://www.csharpfriends.com/Demos/xml_XmlTextReader.xml") );
}
public string ReadXML(string UrlToXmlFile)
{
 // this string will concatenate all the xml values
 System.Text.StringBuilder sbXML = new System.Text.StringBuilder();
 XmlTextReader reader = null;
 try
 {
  // load the file from the URL
  reader = new XmlTextReader(UrlToXmlFile);
 
  object oProvinceName = reader.NameTable.Add("Province");
 
  while (reader.Read())
  {
   if (reader.NodeType == XmlNodeType.Element)
   {
    if (reader.Name.Equals(oProvinceName))
    {
     sbXML.Append(reader.ReadString()).Append("<br />");
    }      
   }
  }
  return sbXML.ToString();
 }
 catch(Exception e)
 {
  Response.Write(e.Message);
  return "";
 }
 finally
 {
 
  if (reader!=null)
   reader.Close();
 }
}
</script>
<html>
 <head>
  <title>CSharpFriends.com - ASP.NET : XmlTextReader</title>
 </head>
 <body>
  <form runat="server" ID="Form1">
  </form>
 </body>
</html>

  <?xml version="1.0" encoding="utf-8" ?>
- <Canada>
  <Province>Alberta</Province>
  <Province>British Columbia</Province>
  <Province>Manitoba</Province>
  <Province>New Brunswick</Province>
  <Province>Newfoundland and Labrador</Province>
  <Province>Northwest Territories</Province>
  <Province>Novia Scotia</Province>
  <Province>Nunavut</Province>
  <Province city="Toronto">Ontario</Province>
  <Province>Prince Edward Island</Province>
  <Province>Quebec</Province>
  <Province>Saskatchewan</Province>
  <Province>Yukon</Province>
  </Canada>

See

http://www.csharpfriends.com/articles/getArticle.aspx?articleID=309&page=2


RJ
0
 
LVL 16

Author Comment

by:OliWarner
ID: 12693610
right , sameish error as before:

System.Net.WebException: The underlying connection was closed: Unable to connect to the remote server.

Basically I'm requesting a page which is on the same server but is dynamic and also in another language so it has to be connected through the server's output...

I'm not sure hot to get around this...
0
 
LVL 9

Expert Comment

by:riyasjef
ID: 12698493
this may be problem with the proxy settings..

Is  ur client is behind a proxy ?

Check tools-->connections-->Internet options-->Lan settings
-->bypass proxy server for local addresses

Is it checked?

RJ
0
 
LVL 9

Expert Comment

by:riyasjef
ID: 12698529
and give absolute path to xml file or asp file

0
 
LVL 16

Author Comment

by:OliWarner
ID: 12699143
that wouldnt let the asp page execte would it?
and no, normal webclients to other servers work fine
0
 
LVL 16

Author Comment

by:OliWarner
ID: 12925460
Well it would be answered but it doesnt quite work.
There's something fishy going on with asp.net requesting things from localhost... it couldnt be to do with nternal portforwarding at my host, but just incase somebody else reads this the answer is mildly incomplete if you get the same problem...

Anyway, ty for the help guys.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does your audience prefer people in photos or no people? How can you best highlight what you’re selling? What are your competitors doing, and what can you do that is different and unique from them?  Continue reading to learn how to make your images …
This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question