Login  •  Register


Basic XML parser

Questions regarding the use of the C++ SDK for Server or Client development or integration into customer products ...

Basic XML parser

Postby alxhoff » 10 Jan 2018, 11:16

Hi all,

I am not the most proficient in C++ and I am hoping to do an uber minimal OPC UA server where a XML file can be read in and the nodes displayed. Its for a proof of concept for a XML generation tool that I would like to get displaying in an OPC UA server, so the server side functionality is not important at all, most importantly that there is some sort of visual representation of the XML in expert.

I have gone through the documentation examples for doing this but it goes way beyond what I want and has left me a little confused. I am hoping to implement a server such that all the information is stored in the XML and one does not need to create the class definitions for the objects that will be in the XML. I am not sure if this is possible, but I am hoping that whatever I put into the XML is then mirrored in an OPC UA server with minimal functionality but so that the nodes can merely be seen in expert.

Is there some sort of generic node manager that can be easily created to create generic nodes off of an XML? I hope my question makes sense and I am trying to do something that is even vaguely possible.

Cheers,

Alex
alxhoff
Full Member
Full Member
 
Posts: 7
Joined: 20 Oct 2017, 09:53

Re: Basic XML parser

Postby alxhoff » 10 Jan 2018, 15:51

Update: I have been able to get what looks like a basic parser going but I am unsure about namespace handling.

I have implemented the following in my servermain.cpp

Code: Select all
   #include "opcserver.h"
   #include "uaplatformlayer.h"
   #include "uathread.h"
   #include "xmldocument.h"
   #include "shutdown.h"
   #include "opcua_basedatavariabletype.h"
   #include "nmtestserver.h"
   #include "nodemanagernodesetxml.h"
   #include "nmxml.h"
   #include "nmxmlcreator.h"
   
   int OpcServerMain(const char* szAppPath)
   {
       int ret = 0;
   
       UaXmlDocument::initParser();
       ret = UaPlatformLayer::init();
   
       if ( ret == 0 )
       {   
           UaString sConfigFileName(szAppPath);
           sConfigFileName += "/ServerConfig.xml";
       
           OpcServer* pServer = new OpcServer;
           pServer->setServerConfig(sConfigFileName, szAppPath);
   
           NmTestServer* pMyNodeManager =  new NmTestServer();
           pServer->addNodeManager(pMyNodeManager);
   
           UaString sNodesetFile(UaString("%1/uanodesetimport.xml").arg(szAppPath));
   
           UaBase::BaseNodeFactory* pBaseNodeFactory = new UaBase::BaseNodeFactory;
   
           NodeManagerNodeSetXmlCreator* pNodeManagerCreator = new NodeManagerNodeSetXmlCreator;
   
           UaNodeSetXmlParserUaNode* pXmlParser = new UaNodeSetXmlParserUaNode(sNodesetFile, pNodeManagerCreator, pBaseNodeFactory,      NULL);
           pServer->addModule(pXmlParser);
   
           ret = pServer->start();
       
           if(ret != 0){
               delete pServer;
               return ret;
           }
       
           printf("***************************************************\n");
           printf(" Press %s to shut down server\n", SHUTDOWN_SEQUENCE);
           printf("***************************************************\n");
       
           while(ShutDownFlag() == 0)
           {
               UaThread::msleep(1000);
           }
           printf("***************************************************\n");
           printf(" Shutting down server\n");
           printf("***************************************************\n");
           pServer->stop(3, UaLocalizedText("", "User shutdown"));
           delete pServer;
           pServer = NULL;
       }   
   
       // Cleanup the UA Stack platform layer
       UaPlatformLayer::cleanup();
       // Cleanup the XML Parser
       UaXmlDocument::cleanupParser();
   
       return ret;
       
   }
 
int main(int argc, char* argv[])
   {
       int ret = 0;
   
       RegisterSignalHandler();
   
       // Extract application path
       char* pszAppPath = getAppPath();
   
       ret = OpcServerMain(pszAppPath);
   
       if ( pszAppPath ) delete [] pszAppPath;
   
       return ret;
   }


In expert I get a single tree with a root node of DemoUANodeSetXML from uanodesetimport.xml

I am wondering why this is showing up?

Cheers
alxhoff
Full Member
Full Member
 
Posts: 7
Joined: 20 Oct 2017, 09:53

Re: Basic XML parser

Postby dhapatkar » 27 Nov 2019, 07:11

I am facing same issue..any answer for same
dhapatkar
Jr. Member
Jr. Member
 
Posts: 4
Joined: 26 Nov 2019, 07:58


Return to C++ based OPC UA SDK

Who is online

Users browsing this forum: No registered users and 0 guests

cron