Reputation: 549
I am very new to Linq to XML. I am trying to get the Element Value of the MSGID Node in this message:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<nsah:AuditHeader xmlns:nsah="http://schemas.rnab.nl/giraal/AuditHeader/1.0">
<To>mq://rifb/accounting/AP</To>
<RelatesTo>mq://rnab/giraal/PE/BookingStatusAPS/01</RelatesTo>
<Action>mq://rifb/accounting/AP/BookingService/01</Action>
<From>mq://rnab/giraal/PE</From>
</nsah:AuditHeader>
</soapenv:Header>
<soapenv:Body>
<ns5:CREATEPMNT_FSFS_REQ xsi:schemaLocation="http://fcubs.ofss.com/service/FCUBSCPGServices CommPmntGtwyCreate-Req-Full.xsd" xmlns:ns5="http://fcubs.ofss.com/service/FCUBSCPGServices">
<ns5:FCUBS_HEADER>
<ns5:SOURCE>SOURCE</ns5:SOURCE>
<ns5:UBSCOMP>FCUBS</ns5:UBSCOMP>
<ns5:MSGID>MsgiD01236549876546351321</ns5:MSGID>
<ns5:USERID>UId</ns5:USERID>
<ns5:BRANCH>BRANCH</ns5:BRANCH>
<ns5:MODULEID>MId</ns5:MODULEID>
<ns5:SERVICE>SERVICE</ns5:SERVICE>
<ns5:OPERATION>Operation</ns5:OPERATION>
<ns5:DESTINATION>Destination</ns5:DESTINATION>
</ns5:FCUBS_HEADER>
<ns5:FCUBS_BODY>
<ns5:PmntDETAILS>
<ns5:XREF>XREF321654987</ns5:XREF>
<ns5:AMOUNT>0.09000</ns5:AMOUNT>
<ns5:VALUE_DATE>2012-12-20</ns5:VALUE_DATE>
<ns5:CCY>EUR</ns5:CCY>
<ns5:CUST_AC_NO>123456789</ns5:CUST_AC_NO>
<ns5:CPTY_AC_NO>987654321</ns5:CPTY_AC_NO>
</ns5:PmntDETAILS>
</ns5:FCUBS_BODY>
</ns5:CREATEPMNT_FSFS_REQ>
</soapenv:Body>
</soapenv:Envelope>
This is what I have at the moment:
Dim XDoc As XDocument = XDocument.Load(Variable_Echo.OpenedFile)
Dim XNs_soapenv As XNamespace = "http://schemas.xmlsoap.org/soap/envelope/"
Dim XNs_ns5 = "http://fcubs.ofss.com/service/FCUBSCPGServices"
Dim Body = XDoc.Descendants(XNs_soapenv + "Body")
Dim MsgId = Body.Descendants(XNs_ns5 + "MSGID")
When I debug my code I get the following errro at the MsgId = "Additional information: The ':' character, hexadecimal value 0x3A, cannot be included in a name."
Help is greatly appreciated
Upvotes: 0
Views: 487
Reputation: 89295
You implicitly declared XNs_ns5
as String. Therefore this : XNs_ns5 + "MSGID"
means concatenated string that represent element name instead of prefix + element name. Because element name should never contains colon (:
), that expression will trigger error. Change declaration of XNs_ns5
to type XNamespace
and the error will go :
Dim XNs_ns5 As XNamespace = "http://fcubs.ofss.com/service/FCUBSCPGServices"
Upvotes: 2