Click here to Skip to main content
15,905,682 members
Home / Discussions / XML / XSL
   

XML / XSL

 
AnswerRe: Why this error when using XML data? Pin
Christian Graus9-Jun-05 15:47
protectorChristian Graus9-Jun-05 15:47 
QuestionImplementation of XML (.NET 1.1) and RemoveChild() - is it a bug ? Pin
lkrzanik9-Jun-05 5:27
lkrzanik9-Jun-05 5:27 
QuestionXML and ASP.NET. How to set this? Pin
shapper9-Jun-05 5:03
shapper9-Jun-05 5:03 
GeneralWhats wrong with this code Pin
Usman Tasleem Akshaf8-Jun-05 20:04
Usman Tasleem Akshaf8-Jun-05 20:04 
GeneralRe: Whats wrong with this code Pin
Christian Graus9-Jun-05 15:54
protectorChristian Graus9-Jun-05 15:54 
GeneralRe: Whats wrong with this code Pin
KaptinKrunch13-Jun-05 19:27
KaptinKrunch13-Jun-05 19:27 
GeneralRename Element(TagName) in DOM Pin
Fastfootskater7-Jun-05 21:41
Fastfootskater7-Jun-05 21:41 
GeneralRe: Rename Element(TagName) in DOM Pin
Fastfootskater8-Jun-05 1:56
Fastfootskater8-Jun-05 1:56 
After spending almost three houres of time
I have found a solution for this "simple" problem

If there are other solutions so tell them.

OK here it is.
In the DOM object there is no possibility to rename the node.
You have to do this in a work around.

- Create an Element Object with the desired name
- Then copy all attributes and childnodes from the target node to the new newelmentnode
- Finally replace the nodes.

In VC++ it looks like this:

BOOL CTssHardwareXml::RenameActualNode( CString strBefore, CString strAfter )
{
HRESULT hr,hr1,hr2;
IXMLDOMNode* pNodeActual = NULL;
IXMLDOMNodeList* pIXMLDOMNodeList = NULL;
IXMLDOMElement* pElementNew = NULL;
IXMLDOMNode* pNodeTemp = NULL;
IXMLDOMNode* pNodeClone = NULL;
IXMLDOMNode* pNodeSuccessFull = NULL;
IXMLDOMNamedNodeMap* pAttributeMapActual = NULL;
IXMLDOMNamedNodeMap* pAttributeMapNew = NULL;
DWORD dwErrorCount = 0;
long lLength = 0;
_bstr_t bstrNodeName = strAfter;
CString strSelctionNode;
strSelctionNode.Format("./%s",strBefore);
BSTR bstrAttributeName;
VARIANT varAttributeValue;


try{
hr = m_pIXMLDOMNode->selectNodes( _bstr_t(strSelctionNode),&pIXMLDOMNodeList);
if(SUCCEEDED(hr) && pIXMLDOMNodeList){
// In this version just only the first one will be renamed !!!!
//-------------------------------------------------------------
hr = pIXMLDOMNodeList->get_item(0,&pNodeActual);
if(!(SUCCEEDED(hr) && pNodeActual)){
dwErrorCount++;
}
pIXMLDOMNodeList->Release();
}

// Create a new Element
hr = m_pIXMLDOMDocument2->createElement( bstrNodeName,&pElementNew);
if( !dwErrorCount && SUCCEEDED(hr) && pElementNew ){
// Copy Attributes from Actual to NewElement
hr1 = pNodeActual->get_attributes(&pAttributeMapActual);
hr2 = pElementNew->get_attributes(&pAttributeMapNew);
if(SUCCEEDED(hr1) && SUCCEEDED(hr2) && pAttributeMapActual && pAttributeMapNew){
hr = pAttributeMapActual->get_length(&lLength);
if(SUCCEEDED(hr)){
//Loop throug Map Attribute
for (long i = 0; i < lLength ;i++){
pNodeTemp = NULL;
pNodeSuccessFull= NULL;
pNodeClone = NULL;
hr = pAttributeMapActual->nextNode(&pNodeTemp);
if(SUCCEEDED(hr) && pNodeTemp){
hr1 = pNodeTemp->get_nodeName(&bstrAttributeName);
hr2 = pNodeTemp->get_nodeValue(&varAttributeValue);
if(SUCCEEDED(hr1) && SUCCEEDED(hr2)){
IXMLDOMAttribute *pIXMLDOMAttribute = NULL;
hr = m_pIXMLDOMDocument2->createAttribute(bstrAttributeName, &pIXMLDOMAttribute);
if(SUCCEEDED(hr) && pIXMLDOMAttribute){
hr = pIXMLDOMAttribute->put_nodeValue(varAttributeValue);
if(SUCCEEDED(hr)){
hr = pAttributeMapNew->setNamedItem(pIXMLDOMAttribute,&pNodeSuccessFull);
if(!(SUCCEEDED(hr) && pNodeSuccessFull))
dwErrorCount++;
else
pNodeSuccessFull->Release();
}
}
}
::SysFreeString(bstrAttributeName);
bstrAttributeName = NULL;
}
}
}
}
// Copy Child nodes if there are existing
hr = pNodeActual->get_childNodes(&pIXMLDOMNodeList);
if(SUCCEEDED(hr) && pIXMLDOMNodeList){
hr = pIXMLDOMNodeList->get_length(&lLength);
if(SUCCEEDED(hr)){
for (long i = 0; i < lLength ;i++){
pIXMLDOMNodeList->get_item(i,&pNodeTemp);
if(SUCCEEDED(hr) && pNodeTemp){
hr = pNodeTemp->cloneNode(VARIANT_TRUE,&pNodeClone);
if(SUCCEEDED(hr) && pNodeClone){
// Now push it to new Element.
hr = pElementNew->appendChild(pNodeClone,&pNodeSuccessFull);
if(!(SUCCEEDED(hr) && pNodeSuccessFull))
dwErrorCount++;
else
pNodeSuccessFull->Release();
}
}
}
}
pIXMLDOMNodeList->Release();
}
// Remove Child nodes
hr = m_pIXMLDOMNode->replaceChild((IXMLDOMNode*)pElementNew,pNodeActual,&pNodeSuccessFull);
if(!(SUCCEEDED(hr) && pNodeSuccessFull)){
dwErrorCount++;
}
}
}
catch(...){
dwErrorCount++;
m_dwErrorCount++;
}

return !dwErrorCount ? TRUE : FALSE;
}
Generalconvert xml file to excel file by using vb6 Pin
YETER737-Jun-05 20:30
YETER737-Jun-05 20:30 
GeneralUsing XML Schemas in C++ Unmanaged Code Pin
RFickling7-Jun-05 16:39
RFickling7-Jun-05 16:39 
GeneralConvert XML/XSL to Image File Pin
pfsarff7-Jun-05 10:55
pfsarff7-Jun-05 10:55 
GeneralRe: Convert XML/XSL to Image File Pin
DavidNohejl7-Jun-05 11:41
DavidNohejl7-Jun-05 11:41 
GeneralRe: Convert XML/XSL to Image File Pin
pfsarff8-Jun-05 4:27
pfsarff8-Jun-05 4:27 
GeneralRe: Convert XML/XSL to Image File Pin
DavidNohejl9-Jun-05 5:24
DavidNohejl9-Jun-05 5:24 
GeneralRe: Convert XML/XSL to Image File Pin
pfsarff9-Jun-05 6:03
pfsarff9-Jun-05 6:03 
GeneralRe: Convert XML/XSL to Image File Pin
DavidNohejl10-Jun-05 9:23
DavidNohejl10-Jun-05 9:23 
GeneralRe: Convert XML/XSL to Image File Pin
Anonymous12-Jun-05 4:27
Anonymous12-Jun-05 4:27 
GeneralXML TO EXCEL Pin
Abhinavbhatia7-Jun-05 1:53
Abhinavbhatia7-Jun-05 1:53 
GeneralRe: Xml programming c# Pin
DavidNohejl7-Jun-05 2:21
DavidNohejl7-Jun-05 2:21 
Generalnested ado datasets in XML Pin
sparty10226-Jun-05 4:50
sparty10226-Jun-05 4:50 
GeneralExport to excel data from ultrawebgrid each row contain one worksheet Pin
sunilmskr3-Jun-05 2:38
sunilmskr3-Jun-05 2:38 
GeneralXSL HTML table and matching tags problem Pin
Leftyfarrell2-Jun-05 4:16
Leftyfarrell2-Jun-05 4:16 
GeneralRe: XSL HTML table and matching tags problem Pin
DavidNohejl2-Jun-05 7:33
DavidNohejl2-Jun-05 7:33 
QuestionHow to remove node Pin
mathuros_paiboon1-Jun-05 15:38
mathuros_paiboon1-Jun-05 15:38 
AnswerRe: How to remove node Pin
Christian Graus1-Jun-05 15:46
protectorChristian Graus1-Jun-05 15:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.