read XML with condition

alseif

New member
Joined
Feb 14, 2012
Messages
3
Programming Experience
Beginner
hi
I have problem can't parse xml to show with condition
it not show any thing in textbox .
help me please....
VB.NET:
Dim xdocaa As XDocument = XDocument.Load("C:\xml\login.xml")        Dim sb As New StringBuilder


        'asuming you have more than 1 plugin in the xml file
        Dim Subjet = From x In xdocaa.Root.Elements Where x.<course>.Value = "Principles of Programming Languages" And x.<subsec>.Value = "800"
        For Each el As XElement In Subjet.<all_topic>.<topic>     'xdocaa.Root.Elements.<all_topic>.<topic>
            sb.AppendFormat("Topic : " & el.<topicname>.Value & Environment.NewLine & _
                            "Description : " & el.<topicdetail>.Value & Environment.NewLine & _
                            "Subject : " & el.<topicadviser>.Value & Environment.NewLine & _
                            "Sec : " & el.<topicdate>.Value & Environment.NewLine & _
                            "--------------------------------------------------" & Environment.NewLine & Environment.NewLine)
        Next
        txtlogin.Text = sb.ToString

read xml forom hear.
VB.NET:
<?xml version='1.0' encoding='TIS-620'?>
<subjects>
	<subject name = "Principles of Programming Languages ">
		<subsec>800</subsec>
		<subdate>F-13-16</subdate>
		<all_topic>
			<topic>
				<topicname>Make Class</topicname>
				<topicdetail>Student's Principle of Programing lang make class in 30/12/2011</topicdetail>
				<topictype>Make</topictype>
				<topicdate>2011-12-18 00:00:00</topicdate>
				<topicadviser>Corets, Eva</topicadviser>
			</topic>
			<topic>
				<topicname>Maeve Ascendant</topicname>
				<topicdetail>After the collapse of a nanotechnology society in England</topicdetail>
				<topictype>Make</topictype>
				<topicdate>2012-02-01 20:36:09</topicdate>
				<topicadviser>Ralls, Kim</topicadviser>
			</topic>
		</all_topic>
	</subject>
	<subject name = "c Programming Languages">
		<subsec>870</subsec>
		<subdate>W-13-16</subdate>
		<all_topic>
			<topic>
				<topicname>Alseif Ascendant</topicname>
				<topicdetail>After the collapse of a nanotechnology society in England</topicdetail>
				<topictype>Make</topictype>
				<topicdate>2012-02-01 20:36:09</topicdate>
				<topicadviser>Ralls, Kim</topicadviser>
			</topic>
		</all_topic>
	</subject>
</subjects>
 
Dim Subjet = From x In xdocaa.Root.Elements Where x.<course>.Value = "Principles of Programming Languages" And x.<subsec>.Value = "800"
What's with the .<course> selection? There is no such element, the text you search for is in the elements .@name attribute.

"Principles of Programming Languages"
is not the same string as
"Principles of Programming Languages "

Since you're using the .<> xml notation I would also select .Root.<subject> rather than .Root.Elements.

You're calling sb.AppendFormat, but you are not actually applying any format, use .AppendLine and get rid of those Environment.NewLine's. That part of code would tidy up and be much more readable.
 
Back
Top