Groups | Blog | Home
all groups > dotnet xml > may 2006 >

dotnet xml : Parsing XML file


ttomes
5/8/2006 1:58:02 PM
I'm trying to parse a XML file and extract a few data elements. I'm having
trouble extracting the exact elements. I get the entire content of the XML
file in the text box currently. I can't figure out how to just get the
elements/attirbutes that I want. This is being done in Visual Web Developer
Express.



The code I have so far is:

Dim sr As New System.IO.StreamReader("C:\test123\upload\" +
FileUpload1.FileName)
Dim xr As New System.Xml.XmlTextReader(sr)
Dim m_xmld = New System.Xml.XmlDocument
Dim m_nodelist As System.Xml.XmlNodeList
Dim m_node As System.Xml.XmlNode
'Dim startdate As System.Xml.XmlNode



'Create the XML Document
'Load the Xml file

m_xmld.Load(xr)
m_nodelist =
m_xmld.SelectNodes("/TestMessage/AuthenticatedPublic/MessageId")


TextBox1.Text = m_xmld.getElementsByTagName("MessageId")



The XML file looks like this (partial):

<?xml version="1.0" encoding="UTF-8"?>
<TestMessage xmlns:dsig="http://www.w3.org/2000/09/xmldsig#"
xmlns:enc="http://www.w3.org/2001/04/xmlenc#">
<AuthenticatedPublic Id="ID_AuthenticatedPublic">
<MessageId>urn:uuid:efeb77ff-eab6-4f4b-8fc8-d1f7293fec91</MessageId>
<MessageType>http://www.test123.com/PROTO-TEST-KDM-20040311#</MessageType>
<AnnotationText>TEST 123</AnnotationText>
<IssueDate>2006-01-30T21:31:32+00:00</IssueDate>
<Signer>

<dsig:X509IssuerName>/dnQualifier=JIQs8tRZIGKLLlyGkKOqMLonGpw=/O=dc.Root.ca.test_rje_xp_laptop.com/OU=test
RJE_XP_LAPTOP/CN=TMS.Test.2A51FBD4-58C2-4955-82FE-8FB31C15C0F7.v0.2.3.0</dsig:X509IssuerName>
<dsig:X509SerialNumber>b5:c9:ac:0a:83:e2:ef:d4
</dsig:X509SerialNumber>
</Signer> <RequiredExtensions>
<Recipient>
<X509IssuerSerial>
<dsig:X509IssuerName/>
<dsig:X509SerialNumber/>
</X509IssuerSerial> <X509SubjectName/>
</Recipient>
<CompositionPlaylistId>urn:uuid:d2b7595e-f852-f246-8c74-3d9724f923a8</CompositionPlaylistId>
<ContentTitleText>StEM_MM_2k_XYZ_CRYPT</ContentTitleText>

<ContentKeysNotValidBefore>2006-01-31T10:00:00+00:00</ContentKeysNotValidBefore>

<ContentKeysNotValidAfter>2006-02-28T09:59:00+00:00</ContentKeysNotValidAfter>

Chakravarthy
5/9/2006 12:43:01 AM
You are doing a mistake while assiging the .TEXT property of the Text box.
Change the code as mentioned below ...

XmlDocument xdTe = new XmlDocument();
xdTe.PreserveWhitespace=true;
xdTe.Load(("C:\test123\upload\" + FileUpload1.FileName);
TextBox1.Clear();
XmlNodeList xnlItems = xdSmp.SelectNodes('//MessageId');
foreach(XmlNode xnSmp in xnlItems)
{
TextBox1.AppendText(xnSmp.InnerXml);
TextBox1.AppendText(Environment.NewLine);
}

Hope this works, it worked for me...
Cheers,
--
Every thing is perfect, as long as you share!!!


[quoted text, click to view]
ttomes
5/9/2006 8:36:01 AM
I changed the code but I still get the entire XML file as the value for the
text box. Can this be a problem with Visual Web Developer 2005 Express
Edition?

I now have the following code:


Dim m_xmld = New System.Xml.XmlDocument
m_xmld.PreserveWhitespace = True
Dim m_nodelist As System.Xml.XmlNodeList
Dim m_node As System.Xml.XmlNode


'Create the XML Document
'Load the Xml file

m_xmld.Load("C:\test123\upload\" + FileUpload1.FileName)
m_nodelist = m_xmld.SelectNodes("//MessageId")

'Loop through the nodes

For Each m_node In m_nodelist
TextBox1.Text = m_xmld.InnerXml
Next

[quoted text, click to view]
Chakravarthy
5/9/2006 10:20:02 PM
Hey,

Look .... there is a small issue with the code... check your foreach look
once again... you should have m_node.innerxml instead of m_xmld.innerxml...

What do you say?
--
Every thing is perfect, as long as you share!!!


[quoted text, click to view]
ttomes
5/10/2006 10:07:03 AM
Ah...those minor details..... Thank you very much for your help.

[quoted text, click to view]
Chakravarthy
5/10/2006 11:29:02 PM
Did my post answer your question?
Was this helpful to you?

If the answer is yes, why dont you click the below buttons?
--
Every thing is perfect, as long as you share!!!


[quoted text, click to view]
AddThis Social Bookmark Button