which I need to be able to parse and retrieve the elements from.
So, newbie question... does anyone have a sample of code that i can use where I pass the xml string as a parameter and then can access each element programatically:
Dim thisResult As
New AuthResponse
Dim xmlDoc As
New Xml.XmlDocument
xmlDoc.LoadXml(XML)
thisResult.ConditionCode = xmlDoc.SelectSingleNode("/AUTHRESP/RESPONSE").Value
thisResult.AuthParm1 = xmlDoc.SelectSingleNode("/AUTHRESP/AUTHPARM1").Value
thisResult.BallotType = xmlDoc.SelectSingleNode("/AUTHRESP/BALLOT").Value
If a build the xml document with de xmldocument.loadxml method I cannot specify the DTD, because the XmlDocumentType cannot be added if there's a root element in the document.
I'm sending a string from a web service client running in eclipse and coding with java to a .net web service written in c#, when I build the string from the .xml file in java, the parse method checked the file against the DTD but exclude the <!DOCTYPE header
from the string, so, when I recieved the string in the web service I have to define de DTD again.
Any ideas about this issue.
Thanks
Paul Hernández
Electronic Engineer
.Net Developer
Computer science PhD Student
I have a Web Service written in c# a published using visual studio 2008.
The ws has a webmethod that recieved 3 xml files and 1 txt file as arguments.
I have to make a client in java with eclipse, so, I installed the axis plugin. This plugin generates the proxy classes usin the WSDL of the .net ws
My first problem was how to interoperate between java and c# because the Xmldocument type in c# is slightly different to the Document type in Java. I decided to change the webmethod to recieved strings instead of xml and text files. Then I wrote a code in
java to convert a xml document into a string and there's no problem with the interoperability of the simple types.
I found a problem parsing the xml files into strings, the java methods use the dtd to build the strings but the <!DOCTYPE XMI SYSTEM "UML_EA.dtd"> was not inserted in the string.
In the ws I recieved each string and converting them into xml files again. The files are the same as the original ones but without the DTD declaration, which is a problem because if I want to search a tag element by an ID, since I'm not defining a dtd the
program does not know what an Id is.
Finally a use a non elegant trick, I took each string as I recieved them and then insert the <!DOCTYPE XMI SYSTEM "UML_EA.dtd"> with the string.insert method and now it's working.
I'm learning a lot with this project but I don't have enough time to do an elegant or brilliant implementation because the deadlines are comming for me jejejej
Regards
Paul
Paul Hernández
Electronic Engineer
.Net Developer
Computer science PhD Student
jmurdock
Participant
1260 Points
402 Posts
Need to parse an xml string into elements
Oct 03, 2006 06:02 PM|LINK
I have an xml string:
<code>
<?xml version="1.0"?><AUTHRESP><RESPONSE>3</RESPONSE><AUTHPARM1>S9801231</AUTHPARM1><BALLOT></BALLOT></AUTHRESP>
</code>
which I need to be able to parse and retrieve the elements from.
So, newbie question... does anyone have a sample of code that i can use where I pass the xml string as a parameter and then can access each element programatically:
ie:
intResponse = parm("RESPONSE")
or some such thing...
thanks.
vcsjones
All-Star
34842 Points
4424 Posts
Moderator
MVP
Re: Need to parse an xml string into elements
Oct 03, 2006 08:09 PM|LINK
System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); doc.LoadXml(@"<?xml version=""1.0""?><AUTHRESP><RESPONSE>3</RESPONSE><AUTHPARM1>S9801231</AUTHPARM1><BALLOT></BALLOT></AUTHRESP>"); System.Xml.XmlNode element = doc.SelectSingleNode("/AUTHRESP/RESPONSE");The example I gave you, element, will select the RESPONSE node with the value of 3.jmurdock
Participant
1260 Points
402 Posts
Re: Need to parse an xml string into elements
Oct 03, 2006 08:57 PM|LINK
Thanks!
I like that.
Easy to understand, very exacting to my needs (my XML string after all), a thing of beauty![:D]
jmurdock
Participant
1260 Points
402 Posts
Re: Need to parse an xml string into elements
Oct 04, 2006 01:09 PM|LINK
Hmmm...
I have tried to create the VB version of this but I have missed something, no errors, just incorrect results. Here is the result information I get
<code>
Raw xml: <?xml version="1.0"?><AUTHRESP><RESPONSE>0</RESPONSE><AUTHPARM1>S980999999</AUTHPARM1><BALLOT>1</BALLOT></AUTHRESP>
Results: AuthParm1 =
Ballot Type: 0
ConditionCode: 0
</code>
and here is the code I used to get it:
<code>
Dim thisResult As New AuthResponse
Dim xmlDoc As New Xml.XmlDocument
xmlDoc.LoadXml(XML)
thisResult.ConditionCode = xmlDoc.SelectSingleNode("/AUTHRESP/RESPONSE").Value
thisResult.AuthParm1 = xmlDoc.SelectSingleNode("/AUTHRESP/AUTHPARM1").Value
thisResult.BallotType = xmlDoc.SelectSingleNode("/AUTHRESP/BALLOT").Value
If Debug = True Then
EventLog.WriteEntry(Me.ServiceName & ".fnParseAuthenticationResp" & vbCrLf & "Raw xml: " & XML & vbCrLf & "Results: AuthParm1 =" & thisResult.AuthParm1 & vbCrLf & "Ballot Type: " & thisResult.BallotType & vbCrLf & "ConditionCode: " & thisResult.ConditionCode, EventLogEntryType.Information)
End If
</code>
Can you see where I am going wrong here? I don't seem to be retrieving the values.
vcsjones
All-Star
34842 Points
4424 Posts
Moderator
MVP
Re: Need to parse an xml string into elements
Oct 04, 2006 01:36 PM|LINK
pauldj54
Member
13 Points
10 Posts
Re: Need to parse an xml string into elements
Jul 15, 2009 02:41 PM|LINK
Hi Kevin:
If a build the xml document with de xmldocument.loadxml method I cannot specify the DTD, because the XmlDocumentType cannot be added if there's a root element in the document.
I'm sending a string from a web service client running in eclipse and coding with java to a .net web service written in c#, when I build the string from the .xml file in java, the parse method checked the file against the DTD but exclude the <!DOCTYPE header from the string, so, when I recieved the string in the web service I have to define de DTD again.
Any ideas about this issue.
Thanks
Electronic Engineer
.Net Developer
Computer science PhD Student
vcsjones
All-Star
34842 Points
4424 Posts
Moderator
MVP
Re: Need to parse an xml string into elements
Jul 15, 2009 03:43 PM|LINK
Maybe I am not understanding, what exactly is it you are trying to do?
pauldj54
Member
13 Points
10 Posts
Re: Need to parse an xml string into elements
Jul 15, 2009 04:51 PM|LINK
I have a Web Service written in c# a published using visual studio 2008.
The ws has a webmethod that recieved 3 xml files and 1 txt file as arguments.
I have to make a client in java with eclipse, so, I installed the axis plugin. This plugin generates the proxy classes usin the WSDL of the .net ws
My first problem was how to interoperate between java and c# because the Xmldocument type in c# is slightly different to the Document type in Java. I decided to change the webmethod to recieved strings instead of xml and text files. Then I wrote a code in java to convert a xml document into a string and there's no problem with the interoperability of the simple types.
I found a problem parsing the xml files into strings, the java methods use the dtd to build the strings but the <!DOCTYPE XMI SYSTEM "UML_EA.dtd"> was not inserted in the string.
In the ws I recieved each string and converting them into xml files again. The files are the same as the original ones but without the DTD declaration, which is a problem because if I want to search a tag element by an ID, since I'm not defining a dtd the program does not know what an Id is.
Finally a use a non elegant trick, I took each string as I recieved them and then insert the <!DOCTYPE XMI SYSTEM "UML_EA.dtd"> with the string.insert method and now it's working.
I'm learning a lot with this project but I don't have enough time to do an elegant or brilliant implementation because the deadlines are comming for me jejejej
Regards
Paul
Electronic Engineer
.Net Developer
Computer science PhD Student