473,387 Members | 3,801 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Parsing XML

Thank you in advance for any and all assistance. It is greatly appreciated.

I am working with Plimus for licensing my software. I can communicate with
the server and I'm getting responses in XML. My question is, the XML stream
that's coming back is telling if it's a successful license registration,
validation, too many installs etc. How do I capture that information and use
in my logic?

I tried:
'If responseContent = "<status>STATUS_CODE</status>" Then

' MessageBox.Show("The key you have enter is either invalid
or you misentered the key. Please try again")
' License.Text = ""
' License.Focus()
'Else
MessageBox.Show(responseContent)
'MessageBox.Show("Thank you for registering. Enjoy your
software!")
'Me.Close()
'Dim frm As Form
'frm = frmEZTechToolsIdentifier
'frm.Show()

but the code doesn't capture the XML stream. What do I need please?

--
Michael Bragg, President
eSolTec, Inc.
a 501(C)(3) organization
MS Authorized MAR
looking for used laptops for developmentally disabled.
Sep 12 '06 #1
4 1990
=?Utf-8?B?ZVNvbFRlYywgSW5jLiA1MDEoYykoMyk=?= <es*****@noemail.nospam>
wrote in news:B5**********************************@microsof t.com:
I tried:
'If responseContent = "<status>STATUS_CODE</status>" Then
Perhaps more data than that is coming back.
>
but the code doesn't capture the XML stream. What do I need please?
Take a look at the System.Text.XML classes - you should load the entire doc
into one of the XML class structures (XML Doc, XML reader, etc) and use
those classes to parse the response. You'll get a more accurate result than
merely text parsing.
Sep 13 '06 #2
Hello Michael,

As for the XML Response stream, how did you get it, through HttpWebRequest
compoent or any other means? Also, before you want to parse the XML
response content, where did you hold the XML content? In a string or a
inmemory stream?

In .net framework, most of the XML processing classes are under the
System.Xml namespace. And you can choose the proper class to maniplate XML
content depend on the format of data you hold. Here are some general
suggestions:

1. If the resposne XML content is held in a string, you can use the
XmlDocument class's "LoadXml" to load it.

#XmlDocument.LoadXml Method
http://msdn2.microsoft.com/en-us/lib...t.loadxml.aspx

2. If the response XML content is in an Stream object (memorystream,
HttpResponseStream....), you can use the XmlDocument.Load method to load it
into XmlDocument.

After you have load the XML content into XmlDocument instance, you can use
its "SelectSingleNode" or "SelectNodes" method to query specific nodes
(through XPATH string) from it and check the certain node's value.

#Select Nodes Using XPath Navigation
http://msdn2.microsoft.com/en-us/library/d271ytdx.aspx

#XML Document Object Model (DOM)
http://msdn2.microsoft.com/en-us/library/hf9hbf87.aspx

For more information about processing XML data in .net framework, you can
refer to the following MSDN reference:

#XML Documents and Data
http://msdn2.microsoft.com/en-us/library/2bcctyt8.aspx
Please feel free to let me know if you have any further specific questions
on this.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.


Sep 13 '06 #3
Thank you for your response. The XML is streamed into a string I believe and
I can give you all the code that's used and that is being returned.
<plimus_licensing_response><status>ERROR_MAXCOUN T</status><days_since_last_assigned>1</days_since_last_assigned><days_till_expiration>358 </days_till_expiration><use_count>1</use_count></plimus_licensing_response>

This is the string information that is returned from the license company.
The part that I need to parse and run logic on is the
<status>ERROR_CODE</status>

Based on the error_code, I need to build the IF Then Else statement to make
the code either open the program, return a message to the user, close the
program and refer the user to the support website.

Here is the code I'm using to return the values.

If Username.Text = "" And eMail.Text = "" And tbxLicense.Text = "" Then
MessageBox.Show("Please enter your registered name.")
Username.Focus()
ElseIf Username.Text <"" And eMail.Text = "" And tbxLicense.Text =
"" Then
MessageBox.Show("Please enter the person's email for this
computer")
eMail.Focus()
ElseIf Username.Text <"" And eMail.Text <"" And tbxLicense.Text
= "" Then
MessageBox.Show("Please enter the license number:
###-####-####-####")
tbxLicense.Focus()
Else
Dim request As Net.HttpWebRequest
Dim response As Net.HttpWebResponse
Dim url As String =
"https://www.plimus.com/jsp/validateKey.jsp?action=REGISTER&productId=#####&ke y="
& tbxLicense.Text & "&action=REGISTER &uniqueMachineId&=" & GetOSProductKey()
& eMail.Text & Username.Text
request = Net.WebRequest.Create(url)
request.Method = "Get"
response = request.GetResponse()
Dim sr As IO.StreamReader = New
IO.StreamReader(response.GetResponseStream())
Dim responseContent As String = sr.ReadToEnd()

sr.Close()
response.Close()
Dim reader As Xml.XmlTextReader = Nothing
tbxResponseContent.Text = responseContent

I've looked at code samples and have started with the Dim reader as
Xml.XmlTextReader = Nothing

The XML response is currently returned to a textbox called
tbxResponseContent.Text. The XML stream is the responseContent.
--
Michael Bragg, President
eSolTec, Inc.
a 501(C)(3) organization
MS Authorized MAR
looking for used laptops for developmentally disabled.
"Spam Catcher" wrote:
=?Utf-8?B?ZVNvbFRlYywgSW5jLiA1MDEoYykoMyk=?= <es*****@noemail.nospam>
wrote in news:B5**********************************@microsof t.com:
I tried:
'If responseContent = "<status>STATUS_CODE</status>" Then

Perhaps more data than that is coming back.

but the code doesn't capture the XML stream. What do I need please?

Take a look at the System.Text.XML classes - you should load the entire doc
into one of the XML class structures (XML Doc, XML reader, etc) and use
those classes to parse the response. You'll get a more accurate result than
merely text parsing.
Sep 13 '06 #4
Thanks for your reply Michael,

For the xml fragment you provide, you can simply use XPATH to query out the
<statuselement and its innerTEXT data. For example, the following code
use xmlDocument to load the xml data from string, and use the
SelectSingleNode to query the node throug XPATH string:

=================================
Dim xmlstring =
"<plimus_licensing_response><status>ERROR_MAXCOUNT </status><days_since_last_
assigned>1</days_since_last_assigned><days_till_expiration>358 </days_till_ex
piration><use_count>1</use_count></plimus_licensing_response>"

Dim doc As New System.Xml.XmlDocument

doc.LoadXml(xmlstring)

Dim node As XmlNode

node = doc.SelectSingleNode("/plimus_licensing_response/status")

If Not node Is Nothing Then
Response.Write("<br/>status: " & node.InnerText)
End If
===================================
BTW, the above xpath string only suit this particular case, for other xml
fragment, you need to calculate the proper xpath when you want to query
other node or nodelist.

Here are some articles introducing XPATH and xpath query in .net framework
XML components:

#XPath Tutorial
http://www.w3schools.com/xpath/

#XPath Selections and Custom Functions, and More
http://msdn.microsoft.com/msdnmag/is...3/02/XMLFiles/

#.NET and XML: XPath Queries
http://www.developer.com/net/net/article.php/3383961

Hope this also helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.


Sep 14 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Gerrit Holl | last post by:
Posted with permission from the author. I have some comments on this PEP, see the (coming) followup to this message. PEP: 321 Title: Date/Time Parsing and Formatting Version: $Revision: 1.3 $...
2
by: Cigdem | last post by:
Hello, I am trying to parse the XML files that the user selects(XML files are on anoher OS400 system called "wkdis3"). But i am permenantly getting that error: Directory0: \\wkdis3\ROOT\home...
16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
0
by: Pentti | last post by:
Can anyone help to understand why re-parsing occurs on a remote database (using database links), even though we are using a prepared statement on the local database: Scenario: ======== We...
9
by: ankitdesai | last post by:
I would like to parse a couple of tables within an individual player's SHTML page. For example, I would like to get the "Actual Pitching Statistics" and the "Translated Pitching Statistics"...
5
by: randy | last post by:
Can some point me to a good example of parsing XML using C# 2.0? Thanks
3
by: toton | last post by:
Hi, I have some ascii files, which are having some formatted text. I want to read some section only from the total file. For that what I am doing is indexing the sections (denoted by .START in...
13
by: Chris Carlen | last post by:
Hi: Having completed enough serial driver code for a TMS320F2812 microcontroller to talk to a terminal, I am now trying different approaches to command interpretation. I have a very simple...
7
by: Daniel Fetchinson | last post by:
Many times a more user friendly date format is convenient than the pure date and time. For example for a date that is yesterday I would like to see "yesterday" instead of the date itself. And for...
1
by: eyeore | last post by:
Hello everyone my String reverse code works but my professor wants me to use pop top push or Stack code and parsing code could you please teach me how to make this code work with pop top push or...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.