Click here to Skip to main content
14,695,504 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to read out an XML file but while reading the child node I am facing difficulty. In the below attached XML file kindly suggest me how to read the child node "UoM" and "Quantity" of Density?

I tried using the foreach loop just as the items for density but that didn't worked out for me. Kindly help me out with this.

Here is the XML file :

    <messagetype>ADD/UPATE ITEM
    <description>Items from ERP to MES
    <creationdatetime>2019-11-09 12:45:10.978
        <itemname>L-Valine 96.5%
        <itemtype>152 Feed Additives Small packaging
        <itemname>Wheat Flour Fine
        <itemtype>101 Feed Materials Large packaging

I have tried the below code but was facing difficulty :


DT = Now();
SQL_Connection = new System.Data.SqlClient.SqlConnection("Server=localhost;Database=NUTRECOM3;User ID=sa;Password=ssmits@1234");

FOR EACH XML_FILES in System.IO.Directory.GetFiles(Me.FilePath,"*Item*.xml");

        Doc = new System.Xml.XmlDocument;

        XMLTBL = doc.NameTable;
        XML_NSM = new System.Xml.XmlNamespaceManager(XMLTBL);

{========================================================APPLICATION AREA=============================================}

MessageType = Doc.SelectSingleNode("/ItemToMES/ApplicationArea/MessageType").InnerText;
Description = Doc.SelectSingleNode("/ItemToMES/ApplicationArea/Description").InnerText;
Sender = Doc.SelectSingleNode("/ItemToMES/ApplicationArea/Sender").InnerText;
Receiver = Doc.SelectSingleNode("/ItemToMES/ApplicationArea/Receiver").InnerText;;
CreationDateTime = Doc.SelectSingleNode("/ItemToMES/ApplicationArea/CreationDateTime").InnerText;
Confirmation = Doc.SelectSingleNode("/ItemToMES/ApplicationArea/Confirmation").InnerText;


dim m_nodelist as System.Xml.XmlNodeList;
dim m_node as System.Xml.XmlNode;
    m_nodelist = Doc.getElementsByTagName("Item");

for each m_node in m_nodelist;

{================================================= READ - FIRST FIELD =================================================}

        ''SQL_FTPC_OBJ_TYPE =Doc.SelectSingleNode("/asx:abap/asx:values/TAB/item/FTPC_OBJ_TYPE",XML_NSM).InnerText;

        ItemCode =m_node.Item("ItemCode").InnerText;

    if (ItemCode == null and ItemCode == "") then
        LogMessage("ItemCode is not having any value");
        LogMessage("ItemCode = " + ItemCode);

What I have tried:

Tried using for each on Density node but that didn't worked out for me
Updated 3-Dec-19 22:39pm
phil.o 4-Dec-19 3:34am
This is neither well-formed XML, nor proper c# code.
Maciej Los 10-Dec-19 15:22pm
Short And To The Point!
RickZeeland 4-Dec-19 4:57am
Do you want the VB.NET code to work with the malformed XML, or can you get a proper XML file?
Richard Deeming 4-Dec-19 10:10am
Your application should not be connecting to SQL as sa. That's an unrestricted user account which could be used to destroy your database, your server, or even your network.

And I hope that's not your real sa password you've just posted to a public forum?! If it is, you should change it immediately. And this time, chose a strong password, rather than something that could be cracked in a few minutes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900