Hi, There,
I need to describe the structre of many cells, e.g. what each text with enter data field is used for my application. I can think of two ways:
1. Create a xml file to describe each cell.
2. Add am XML element to the header of each cell to describe its structure.
I have never used mdlXMLxxx functions before, I would like some advice which way I should go and pro and cons of each approach. I could not find any sample applications. If someone can provide some sample applications, it would be greatly appreciated.
Thanks in advance.
Ken
// in class header private: tstring m_strFragment; XmlDomRef m_oDomRef; XmlNodeRef m_oRootNodeRef; XMLFragmentIDs m_nFragmentID; }
////////////////////////////////////////////////////////////////////// bool CXMLFragment::AddCellName ( XMLFragmentListP pFragmentList, // => Add table's cell-name ElementDescrConstP pTable // => Table descriptor ) { bool rc = false; MSWChar cellName [MAX_MODEL_NAME_LENGTH]; if (SUCCESS == mdlCell_extractName (cellName, MAX_MODEL_NAME_LENGTH, &pTable->gt;el)) { wstring XPath (wXPATH_HEADER_CONTENT); XmlNodeRef oInsertNode = NULL; if (SUCCESS == mdlXMLDom_selectSingleNode (&oInsertNode, m_oDomRef, XPath.c_str ())) { XmlNodeRef oCellName = NULL; if (SUCCESS == mdlXMLDom_insertElement (&oCellName, m_oDomRef, oInsertNode, XMLDATATYPE_WIDESTRING, wXML_CELL_NAME, cellName)) { mdlXMLDomNode_free (oCellName); rc = true; } } mdlXMLDomNode_free (oInsertNode); } return rc; }
m_oDomRef is a class member variable. Initialise it like this …
bool CXMLFragment::InitDom ( LPCWSTR nodeName ) { bool rc = false; if (SUCCESS == mdlXMLDom_create (&m_oDomRef)) { if (SUCCESS == mdlXMLDom_createElement (&m_oRootNodeRef, m_oDomRef, nodeName) && SUCCESS == mdlXMLDom_setRootElement (m_oDomRef, m_oRootNodeRef)) { rc = true; } } return rc; }
Regards, Jon Summers LA Solutions
Hi, Jon,
Thanks for your help. I can see you are using C++. I am still using "pure" MDL. In order to follow your sample, I put the following code in my test application:
#include <mdlxml.h>
#include <mdlxmltools.h>
char m_strFragment[255];
XmlDomRef m_oDomRef;
XmlNodeRef m_oRootNodeRef;
XMLFragmentIDs m_nFragmentID;
LPCWSTR nodeName = L"KwNode";
bool rc = false;
if (SUCCESS == mdlXMLDom_create (&m_oDomRef))
{
if (SUCCESS == mdlXMLDom_createElement (&m_oRootNodeRef, m_oDomRef, nodeName)
&&
SUCCESS == mdlXMLDom_setRootElement (m_oDomRef, m_oRootNodeRef))
rc = true;
}
However, I could not compile the code. It generated a lot of error like the one below:
C:\PROGRA~1\Bentley\2004\Program\MICROS~1\mdl\include\mdlxmltools.h(33) : error: expected expression.
I checked the mdlxmltools.h file. The trouble making lines are as follows:
typedef struct CXmlDom* XmlDomRef;
typedef struct CXmlNamedNodeMap* XmlNamedNodeMapRef;
typedef struct CXmlNode* XmlNodeRef;
typedef struct CXmlNodeList* XmlNodeListRef;
It looked like the compiler could not pick up CXmlDom, etc. Which header file/s did I missed?
Your advise will be greatly appreciated?
Unknown said: #include <mdlxml.h> #include <mdlxmltools.h>
You probably need to #include the function definition files (*.fdf). Look at the documentation for the XML functions: you need, for example, <mdlxmltools.fdf>. If you need more help, copy the compiler message here.
Unknown said:typedef struct CXmlNode* XmlNodeRef;
MDL uses opaque pointers frequently. Another example is a DialogItem*. We can't see the structure of an XmlNode, nor do we want to — the API provides all we need.
After I removed the headers and added
#include <mdlxml.fdf>
#include <mdlxmltools.fdf>
I got the following compiling error:
C:\PROGRA~1\Bentley\Program\MICROS~1\mdl\include\msscancrit.h(53) : error: expected expression.
I am totally confused.
Best call it a day, a long long day.
Unknown said:I am totally confused
Writing MDL provides many opportunities to become confused. Writing code that uses any large, complex, library is often bewildering, particularly when it comes to decrypting error messages. Just wait until you see the kind of errors that C++ can produce ...
If you look at the files in \MicroStation\mdl\include to find mdlxml.fdf, you will see that it in turn #includes msscancrit.h. That file is obviously missing something. Often, it's a typedef that is available in some other header file.
What is on line 53 of msscancrit.h?
I put the following code in a new test file
if ( SUCCESS != mdlXMLDom_create(&pDomRef) )
mdlDialog_openInfoBox("ERROR: failed to create a pDomRef");
else
mdlDialog_openInfoBox("INFO: Create a pDomRef");
It passed compiling. Still confused with what happened before.
Thanks for your help