By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,375 Members | 3,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,375 IT Pros & Developers. It's quick & easy.

how to get string within string

P: 12
Hi,

I really need you guys' help with getting string within string. I have an address validation code that will send a request string to UPS, and if the address is validated, UPS will send a response string back. The problem starts here. Once I get the response string, I want to be able to display only city, state and zipcodes, but I don't know how to grab those values from the response string. The response string looks like this:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0"?>
  2. <AddressValidationResponse>
  3. <Response>
  4. <TransactionReference>
  5. <CustomerContext>Customer Data</CustomerContext>
  6. <XpciVersion>1.0001</XpciVersion></TransactionReference>
  7. <ResponseStatusCode>1</ResponseStatusCode>
  8. <ResponseStatusDescription>Success</ResponseStatusDescription></Response>
  9. <AddressValidationResult>
  10. <Rank>1</Rank>
  11. <Quality>0.9254</Quality>
  12. <Address>
  13. <City>MADISON</City>
  14. <StateProvinceCode>WI</StateProvinceCode></Address>
  15. <PostalCodeLowEnd>53701</PostalCodeLowEnd>
  16. <PostalCodeHighEnd>53708</PostalCodeHighEnd></AddressValidationResult></AddressValidationResponse> 
So, the only values I want to display are (for example)Madison, WI, 53702, 53708.

Thanks
aboon
Feb 16 '09 #1
Share this Question
Share on Google+
8 Replies


vekipeki
Expert 100+
P: 229

P: 12
@vekipeki
Hi, Thanks for the link..I still couldn't get it to work because the XmlReader get text from a file, but the response string I got from UPS does not store in a file. I'm not sure how to just read a string within that string. I tried using SubString, but that didn't work either because the the length of the response string is not consistent. It depends on the values that user type in, and the result of the validation.

please help,
thanks
Feb 17 '09 #3

tlhintoq
Expert 2.5K+
P: 3,525
I've never used XML before (shock) and yet I can see there are 12 overrides for the .Create method - several of them use a System.IO.Stream as the source. So you are not limited to just reading XML files from hard disc.

I would think you can take your incoming data, turn it into a stream if it isn't already, and then feed it to the .Reader object.

TIP:
If you aren't accustomed to it, use the tools that Visual Studio gives you, such as the Intellisense.

As you start typing 'XMLReader.' as soon as you hit the period a list of available methods and properties comes up. Type 'Create(', then as soon as you type the left parenthises ( a list of all the overides comes up showing you all the various ways you can call this method with different combinations of arguments. You can hit the up/down arrow keys or click on the up/down arrows of the hothelp that just popped up to see the different overrides.
Feb 17 '09 #4

P: 12
I'm not sure how to do it exactly..
This is part of the code.after I got user input(city, state, zip), send the request string to UPS to validate the address.
UPSOnlineInterface.Components.Address addr = new UPSOnlineInterface.Components.Address();
addr.City = this.txtCity.Text.Trim();
addr.StateProvinceCode = this.ddlState.SelectedValue;
addr.PostalCode = this.txtZip.Text.Trim();
string response = reques.AddressValidateRequest(accReq, addr);
string encodedString = HttpUtility.HtmlEncode(response).Replace("&lt;", "<BR>&lt;").Replace("<BR>&lt;/", "&lt;/");
The "encodingString" is the result of the response string which looks like the top post..the next step is to get the values, and dispay them which I still couldn't figure out.

thanks
Feb 17 '09 #5

vekipeki
Expert 100+
P: 229
there are 12 overrides for the .Create method
As tlhintoq said, using Intellisense can help you find the override that works for you - using the up/down keys you will browse through different tooltips for that method.

Note the Intellisense tooltip in the figure below:



In this case, your method accepts a TextReader, so it means you can create a StringReader from your string and pass it to your method (because StringReader is a concrete implementation of abstract TextReader class).
Feb 18 '09 #6

P: 12
In this case, your method accepts a TextReader, so it means you can create a StringReader from your string and pass it to your method (because StringReader is a concrete implementation of abstract TextReader class).
Hello,
Thanks you very much for the example. I tried using StringReader and get the innerXml as a result.
Expand|Select|Wrap|Line Numbers
  1.  XmlDocument xmlDoc = new XmlDocument();
  2.         xmlDoc.Load(new StringReader(response));
  3.         XmlNode elem = xmlDoc.DocumentElement;
The innerXml looks something like this:
Customer Data1.00011Success10.9169
MADISONWI
535625356220.9169
MADISONWI
535935359330.9169
MADISONWI
537015370840.9169
MADISONWI
537115371150.9169
MADISONWI

Now, I would like to add the innerXml result into a dropdownlist. Is there a way to do this???

Thank you very much for all your help.
aboon
Feb 20 '09 #7

tlhintoq
Expert 2.5K+
P: 3,525
Expand|Select|Wrap|Line Numbers
  1. ComboBox bob = new ComboBox();// Or use an existing control
  2. string MyNewItem = MyXMLcalculationMethod();// Your method that parses the XML and returns a string to be added to the ComboBox
  3. bob.Items.Add(MyNewItem);
  4.  
Feb 21 '09 #8

P: 12
thank you very much for all your help
Feb 24 '09 #9

Post your reply

Sign in to post your reply or Sign up for a free account.