Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

c# asp.net xml

Posted on 2011-03-10
9
Medium Priority
?
267 Views
Last Modified: 2012-06-27
I have attached xml code that saved in the database(SQL Server 2008).
Basically, I just need to get value of <MCFloorRate></MCFloorRate>.

My question is: How can I write a Void to do the following
like Void Result
{
Result = ValueofMCfllooRate;
}

I am not .net programmer.so if you can send me working code, 500 pts is yours.
<DATA>
<FuelSurchargeGroup>1</FuelSurchargeGroup>
<MCFloorRate>125.00</MCFloorRate>
<HazMatPercentage>0</HazMatPercentage>
<HotPercentage>0</HotPercentage>
<TLMilePrice>0</TLMilePrice>
<TLWeight>0</TLWeight>
<TLChargeType>0</TLChargeType>
<LTLChargeType>1</LTLChargeType>
<LTLPalletMaxWeight>0</LTLPalletMaxWeight>
<LTLSmallPalletMaxWeight>0</LTLSmallPalletMaxWeight>
<UseDefaultTLStates>False</UseDefaultTLStates>
<UseDefaultClasses>False</UseDefaultClasses>
<UseDefaultStates>True</UseDefaultStates>
<UseDefaultAccessorial>False</UseDefaultAccessorial>
<UseDefaultDiscount>False</UseDefaultDiscount>
<ShowDescountOnInvoice>True</ShowDescountOnInvoice>
<Terms>Net 15</Terms><TLSTATES />
<CLASSES><CLASS><GID>ec13ab3e-1008-4278-a784-66f1615d58a9</GID>
<START>100</START>
<END>150</END>
<VALUE>100</VALUE>
</CLASS></CLASSES>
<STATES />
<Accessorials><Accessorial>
<ID>1</ID>
<Text>Appointment Delivery</Text>
<Value />
</Accessorial><Accessorial>
<ID>2</ID><Text>COD Charge</Text><Value /></Accessorial><Accessorial><ID>3</ID><Text>Inside Delivery Charge</Text><Value /></Accessorial><Accessorial><ID>4</ID><Text>Liftgate Service</Text><Value /></Accessorial><Accessorial><ID>5</ID><Text>Redelivery Charge</Text><Value /></Accessorial><Accessorial><ID>6</ID><Text>Rural Pickup &amp; Delivery</Text><Value /></Accessorial></Accessorials><DISCOUNTS><DISCOUNT><GID>150bcfc5-f89d-442c-9859-25339ec72eb6</GID><START>1</START><END>14999</END><VALUE>81</VALUE></DISCOUNT></DISCOUNTS><CreatedDate>8/2/2009 12:13:49 PM</CreatedDate><UpdatedDate>8/27/2009 10:02:42 AM</UpdatedDate><UpdatedBy>0d6c6004-5688-4fb6-b369-3b15c77f3cbd</UpdatedBy></DATA>

Open in new window

0
Comment
Question by:Webboy2008
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 2

Expert Comment

by:computeras
ID: 35099065
Try this out:

private void result()
{
   XmlDocument xml = new XmlDocument();
   xml.Load(myXmlPath); // the path of your xml file
   // you can use xml.LoadXml(xmlText); if xmlText contains all of your xml
   result = xml.SelectSingleNode("/DATA/MCFloorRate").InnerText;
}

Open in new window

0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35099068
Assuming you are loading your XML from a string rather from disk:
public string GetXmlValue()
{
    string retVal = string.Emtpy;

    XmlDocument doc = new XmlDocument();
    doc.LoadXml("your_xml_string");

    XmlNode node = doc.SelectSingleNode("//MCFloorRate");
    if (node != null)
         retVal = node.InnerText;

    return retVal;
}

Open in new window

0
 

Author Comment

by:Webboy2008
ID: 35099118
The issue is. it is now in the table column called xmlbilling in customers table.
I don't know how to write the code and capture the data there
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 

Author Comment

by:Webboy2008
ID: 35099128
like select xmlbilling from customers where customerId = 1
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35099170
SqlConnection cn = new SqlConnection("your connection string");
SqlCommand cmd = new SqlCommand("SELECT xmlbilling FROM customers WHERE customerId = 1", cn);

cn.Open();
string xml = (string)cmd.ExecuteScalar();
cn.Close();

XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);

string value = string.Empty;

XmlNode node = doc.SelectSingleNode("//MCFloorRate");
if (node != null)
    value = node.InnerText;

Open in new window

0
 

Author Comment

by:Webboy2008
ID: 35099714
Guys. Thank you very much for your helps. I am able to make it in Void based on your given...
However, I am unable to make return to int.

Can you please take a look? Basic, I just want call/return in int. the number value may go under to 20000
protected void Page_Load(object sender, EventArgs e)
    {
	string ReturnValue= ReturnCustomerMc(121);
    Response.Write(ReturnValue.ToString());
    }
    
    public string ReturnCustomerMc(int CustomerId)
    {
     string value1;
     SqlConnection cn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ManageRolesConnectionString"].ToString());
	 SqlCommand cmd = new SqlCommand("SELECT xmlbilling FROM customers WHERE Id = 121", cn);
	 cn.Open();
	 string xml = (string)cmd.ExecuteScalar();
	 cn.Close();
	 XmlDocument doc = new XmlDocument();
     doc.LoadXml(xml);
     string value = string.Empty;
     XmlNode node = doc.SelectSingleNode("//MCFloorRate");
     if (node != null)
     {
     value1 = node.InnerText;
     return value1;
     }
     else
     {
     return "0";
     }
    }

Open in new window

0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35099755
protected void Page_Load(object sender, EventArgs e)
    {
	int ReturnValue= ReturnCustomerMc(121);
    Response.Write(ReturnValue.ToString());
    }
    
    public int ReturnCustomerMc(int CustomerId)
    {
     int value1 = 0;
     SqlConnection cn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ManageRolesConnectionString"].ToString());
	 SqlCommand cmd = new SqlCommand("SELECT xmlbilling FROM customers WHERE Id = 121", cn);
	 cn.Open();
	 string xml = (string)cmd.ExecuteScalar();
	 cn.Close();
	 XmlDocument doc = new XmlDocument();
     doc.LoadXml(xml);
     string value = string.Empty;
     XmlNode node = doc.SelectSingleNode("//MCFloorRate");
     if (node != null)
     {
     value1 = int.Parse(node.InnerText);
     }

     return value1;

Open in new window

0
 

Author Comment

by:Webboy2008
ID: 35099809
carl_tawn: Input string was not in a correct format.
0
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 35099870
Your sample XML is showing the number as having a decimal, so you will need to use a floating point type rather than a simple int:
protected void Page_Load(object sender, EventArgs e)
    {
	float ReturnValue= ReturnCustomerMc(121);
    Response.Write(ReturnValue.ToString());
    }
    
    public float ReturnCustomerMc(int CustomerId)
    {
     float value1 = 0;
     SqlConnection cn = new SqlConnection(WebConfigurationManager.ConnectionStrings["ManageRolesConnectionString"].ToString());
	 SqlCommand cmd = new SqlCommand("SELECT xmlbilling FROM customers WHERE Id = 121", cn);
	 cn.Open();
	 string xml = (string)cmd.ExecuteScalar();
	 cn.Close();
	 XmlDocument doc = new XmlDocument();
     doc.LoadXml(xml);
     string value = string.Empty;
     XmlNode node = doc.SelectSingleNode("//MCFloorRate");
     if (node != null)
     {
     value1 = float.Parse(node.InnerText);
     }

     return value1;
}

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

688 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