PC Review


Reply
Thread Tools Rate Thread

XPath help!!!

 
 
rsine
Guest
Posts: n/a
 
      13th Jun 2007
I have been working for hours trying to get an XPath query to work.
At first, I thought it was the namespaces causing me issues, but I
added an xmlNameSpacesManager and still cannot get my code to work. I
keep getting a NullReferenceException. Any help would be appreciated
as this has been really frustrating. -Thanks

The following is my VB.Net code:

Dim xmlDoc As New System.Xml.XmlDocument
Dim xmlNode As System.Xml.XmlNode
Dim xmlNSM As System.Xml.XmlNamespaceManager
Dim FromID As String

'load the xml document
xmlDoc.Load("C:\my.xml")

'establish the namespace manager
xmlNSM = New System.Xml.XmlNamespaceManager(xmlDoc.NameTable)
For Each attr As System.Xml.XmlAttribute In
xmlDoc.SelectSingleNode("/*").Attributes
If attr.Prefix = "xmlns" Then
xmlNSM.AddNamespace(attr.LocalName, attr.Value)
End If
Next attr

'set default namespace
xmlNSM.AddNamespace("", "http://www.icsm.com/icsmxml")
xmlNSM.PushScope()

'move to the root node
xmlNode = xmlDoc.DocumentElement

'find the FROM id
Try
FromID = xmlNode.SelectSingleNode("./Header/MsgDelivery/From/
Credential/Identity", xmlNSM).InnerText.Trim.ToUpper
Catch ex As Exception
Throw ex
End Try


The xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<ICSMXML xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://
www.icsm.com/icsmxml">
<Header>
<MsgDelivery>
<To>
<Credential>
<Domain>ToDomain</Domain>
<Identity>ToIdentity</Identity>
</Credential>
</To>
<From>
<Credential>
<Domain>FromDomain</Domain>
<Identity>FromIdentity</Identity>
</Credential>
</From>
<Sender>
<Credential>
<Domain>SenderDomain</Domain>
<Identity>SenderIdentity</Identity>
</Credential>
</Sender>
</MsgDelivery>
<MsgHeader>
<MessageId>test</MessageId>
<Timestamp>00:00:00</Timestamp>
<ResponseTo></ResponseTo>
<DocumentId>DocumentID</DocumentId>
</MsgHeader>
<ConversationState>
<AgreementId>Agreement</AgreementId>
<ConversationId>Conversation</ConversationId>
</ConversationState>
</Header>
<Request>
<Message>This is my Message</Message>
</Request>
</ICSMXML>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath, XML and other David Microsoft C# .NET 2 25th Nov 2005 01:58 PM
XPath with ADO XML mjwills Microsoft VB .NET 1 24th Oct 2005 09:24 AM
Need XPath help =?Utf-8?B?UmljaGFyZA==?= Microsoft C# .NET 2 4th Oct 2005 10:46 PM
Xpath For Xml Map WStoreyII Microsoft Excel Programming 0 6th Aug 2004 04:11 AM
3rd party xpath for CF (e.g. cuesoft xpath) Yechezkal Gutfreund Microsoft Dot NET Compact Framework 0 6th Nov 2003 02:36 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:05 PM.