I have the code below that looks at an XML file to find a node named IssueMaterialPO and finds it successfully in the XML listed in the second code block. It doesn't find anything in the XML in the third code block. I have tried various search strings in the SelectSingleNode argument, all with no luck. I'm not sure if my search is wrong, if it's something to do with the namespace, or something else entirely. I'm new to working with XML and am not sure what to try next.
Code:Try Dim doc As New XmlDocument doc.Load(myXMLfile) Dim nsMgr As New XmlNamespaceManager(doc.NameTable) nsMgr.AddNamespace( "ext_UserSchema", "http://Epicor.com/SC/UserSchema/" ) nsMgr.AddNamespace( "msg", "http://Epicor.com/Message/2.0" ) Dim nodeToFind As XmlNode Dim root As XmlElement = doc.DocumentElement nodeToFind = root.SelectSingleNode( "//IssueMaterialPO", nsMgr) If (nodeToFind Is Nothing) Then MsgBox( "Not Found") Else IMPO = True MsgBox( "Found") End If
Finds IssueMaterialPO in this block
Doesn't find IssueMaterialPO in this blockCode:<?xml version="1.0" encoding="ISO8859-1" ?> <BatchRecord> <RecordNumber>11340</RecordNumber> <Date>2012-03-09</Date> <ERP> <Transactions> <IssueMaterialPO> <Bin>BIN</Bin> <OrderNumber>555555</OrderNumber> <InventoryCategory>O</InventoryCategory> <LotNumber>678</LotNumber> <ItemNumber>12-345</ItemNumber> <Quantity>10</Quantity> <Stockroom>01</Stockroom> </IssueMaterialPO> </Transactions> </ERP> </BatchRecord>
Code:<?xml version="1.0" encoding="utf-16"?> <msg:Msg xsi:schemaLocation="http://Epicor.com/Message/2.0 http://scshost/schemas/epicor/ScalaMessage.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:msg="http://Epicor.com/Message/2.0"> <msg:Hdr> <msg:Ctrl> <msg:MsgID></msg:MsgID> </msg:Ctrl> <msg:Sender> <msg:Name></msg:Name> <msg:Subname></msg:Subname> </msg:Sender> <msg:Logon></msg:Logon> </msg:Hdr> <msg:Body> <msg:Req msg-type="transaction" action="ConvertXML"> <msg:Dta> <ext_UserSchema:BatchRecord xmlns:msg="http://Epicor.com/InternalMessage/1.1" xmlns:ext_UserSchema="http://Epicor.com/SC/UserSchema"> <ext_UserSchema:RecordNumber>11340</ext_UserSchema:RecordNumber> <ext_UserSchema:Date>2012-03-09</ext_UserSchema:Date> <ext_UserSchema:ERP> <ext_UserSchema:Transactions> <ext_UserSchema:IssueMaterialPO> <ext_UserSchema:Bin>BIN</ext_UserSchema:Bin> <ext_UserSchema:OrderNumber>555555</ext_UserSchema:OrderNumber> <ext_UserSchema:InventoryCategory>O</ext_UserSchema:InventoryCategory> <ext_UserSchema:LotNumber>678</ext_UserSchema:LotNumber> <ext_UserSchema:ItemNumber>12-345</ext_UserSchema:ItemNumber> <ext_UserSchema:Quantity>10</ext_UserSchema:Quantity> <ext_UserSchema:Stockroom>01</ext_UserSchema:Stockroom> </ext_UserSchema:IssueMaterialPO> </ext_UserSchema:Transactions> </ext_UserSchema:ERP> </ext_UserSchema:BatchRecord> </msg:Dta> </msg:Req> </msg:Body> </msg:Msg>


Reply With Quote
