Click here to Skip to main content
15,849,829 members
Home / Discussions / XML / XSL
   

XML / XSL

 
Questionlanguage localization using XML in VC++ (MFC) Pin
punyah20108-May-10 10:03
punyah20108-May-10 10:03 
QuestionSuppress Xmlns in InnerXML / Rename an XML node in DOM Pin
Ger Hayden6-May-10 12:37
Ger Hayden6-May-10 12:37 
Suppress Xmlns in InnerXML / Rename an XML node in DOM
The Original:

<?xml version="1.0" encoding="utf-8"?>
<EntrySummaryDeclaration xmlns="http://www.gph.ie/schemas/ics/IE315/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gph.ie/schemas/ics/IE315/v1 C:/GPH/Schemas/IE315/v1/schema.xsd">
<Declaration>
:
:
</Declaration>
</EntrySummaryDeclaration>

The Required new output
<?xml version="1.0" encoding="utf-8"?>
<EntrySummaryDeclarationAmendment xmlns="http://www.gph.ie/schemas/ics/IE313/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.gph.ie/schemas/ics/IE313/v1 C:/GPH/Schemas/IE313/v1/schema.xsd">
<Declaration>
:
:
</Declaration>
</ EntrySummaryDeclarationAmendment >

The Actual New Output
<?xml version="1.0" encoding="utf-8"?>
<EntrySummaryDeclarationAmendment xmlns="http://www.gph.ie/schemas/ics/IE313/v1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" schemaLocation="http://www.gph.ie/schemas/ics/IE313/v1 http://wlhost2:38711/xmlreferencesite/customs/ics/IE313-EntrySummaryDeclarationAmendment/v1/schema.xsd C:/GPH/Schemas/IE313/v1/schema.xsd">
<Declaration xmlns="http://www.gph.ie/schemas/ics/IE313/v1">
</Declaration></EntrySummaryDeclarationAmendment>

The approach
I am using DOM, so I cant rename EntrySummaryDeclaration, therefore I create a new EntrySummaryDeclarationAmendment node, and I assign the inner xml of EntrySummaryDeclaration to the inner xml of EntrySummaryDeclarationAmendment before deleting EntrySummaryDeclaration.

The problem:
The innerXml insists on bringing its original xmlns with it.

The requested solution:
How do I suppress the xmlns in the innerxml – removing it as an attribute after the fact has no effect?
Alternatively – how would I rename EntrySummaryDeclaration as EntrySummaryDeclarationAmendment easly?

The offending Code
XmlNode ^TmpNode;
XmlNode ^IE315_Node;
XmlNode ^IE313_Node;
XmlAttribute ^att;
String^ tmpstr;



if (current_message == MessageType::IE315)
{

if (!namespace_found)
try
{
IE315_Node = doc->SelectSingleNode("//EntrySummaryDeclaration");
}
catch (Exception ^e)
{
MessageString = "Error finding EntrySummaryDeclaration: " + e->Message;
MessageBox::Show(MessageString);
}
else
try
{
IE315_Node = doc->SelectSingleNode("//ie:EntrySummaryDeclaration",nsmgr);
}
catch (Exception ^e)
{
MessageString = "Error finding EntrySummaryDeclaration: " + e->Message;
MessageBox::Show(MessageString);
}

// Create node EntrySummaryDeclarationAmendment
IE313_Node = doc->CreateElement("EntrySummaryDeclarationAmendment");

// Set up the attributes
att = doc->CreateAttribute("xmlns");
att->Value = "http://www.GPH.ie/schemas/ics/IE313/v1";
IE313_Node->Attributes->Append(att);

att = doc->CreateAttribute("xmlns:xsi");
att->Value = "http://www.w3.org/2001/XMLSchema-instance";
IE313_Node->Attributes->Append(att);

tmpstr = "http://www.GPH.ie/schemas/ics/IE313/v1"; // the namespace
DocNamespace = tmpstr;
//Add the new namespace to the document
nsmgr = gcnew XmlNamespaceManager (doc->NameTable);
nsmgr->AddNamespace(L"xsi","http://www.w3.org/2001/XMLSchema-instance");

namespace_found = true;
// if there is no local schema specified, include a default.

tmpstr += " http://wlhost2:38711/xmlreferencesite/stuff/IE313-EntrySummaryDeclarationAmendment/v1/schema.xsd";
SchemaBar->Text = "Schema: http://wlhost2:38711/xmlreferencesite/stuff/IE313-EntrySummaryDeclarationAmendment/v1/schema.xsd";
SchemaName = "http://wlhost2:38711/xmlreferencesite/stuff/IE313-EntrySummaryDeclarationAmendment/v1/schema.xsd";
// Debug schema used for development
MessageString = "NOTE: Using DEBUG Schema!!!";
MessageBox::Show(MessageString);
//C:/GPH/Schemas/IE313/v1/schema.xsd
tmpstr += " C:/GPH/Schemas/IE313/v1/schema.xsd";
SchemaBar->Text = "Schema: C:/GPH/Schemas/IE313/v1/schema.xsd";
SchemaName = "C:/GPH/Schemas/IE313/v1/schema.xsd";
doc->Schemas->Add(DocNamespace,SchemaName);
doc->Schemas->ValidationEventHandler+=eventHandler;
nsmgr->AddNamespace(L"ie", DocNamespace);


schema_found = true;

att = doc->CreateAttribute("xsi:schemaLocation");
att->Value = tmpstr;
IE313_Node->Attributes->Append(att);


// Copy contents of EntrySummaryDeclaration to EntrySummaryDeclarationAmendment
IE313_Node->InnerXml = IE315_Node->InnerXml;

// Delete EntrySummaryDeclaration
Delete_Node(IE315_Node);




/* // Remove any attributes from the Declaration node
if (namespace_found)
try
{
//TmpNode = IE313_Node->FirstChild;//doc->SelectSingleNode("//ie:Declaration",nsmgr);
if (IE313_Node->FirstChild->Name == "Declaration")
{
for (int i = 0; i < IE313_Node->FirstChild->Attributes->Count; i++)
{
MessageString = "Element Node: " + IE313_Node->FirstChild->Name + "; attribute[" + i + "]: Name = "
+ IE313_Node->FirstChild->Attributes[i]->Name
+ "; Value = " + IE313_Node->FirstChild->Attributes[i]->Value;
MessageBox::Show(MessageString);
IE313_Node->FirstChild->Attributes[i]->RemoveAll();
}
IE313_Node->FirstChild->Attributes->RemoveAll();
// doc->Attributes->Remove(IE313_Node->FirstChild->Attributes[0]);
XmlAttributeCollection^ attrs;
attrs = IE313_Node->FirstChild->Attributes;
attrs->RemoveAll();

}
}
catch (Exception ^e)
{
MessageString = "Error finding Declaration: " + e->Message;
MessageBox::Show(MessageString);
}*/



// Add the new EntrySummaryDeclarationAmendment node
doc->AppendChild(IE313_Node);


}
Ger

AnswerRe: Suppress Xmlns in InnerXML / Rename an XML node in DOM Pin
Ger Hayden8-May-10 8:24
Ger Hayden8-May-10 8:24 
QuestionParsing RSS Pin
Aljaz1116-May-10 4:37
Aljaz1116-May-10 4:37 
AnswerRe: Parsing RSS Pin
Stuart Dootson7-May-10 0:24
professionalStuart Dootson7-May-10 0:24 
QuestionXSLT to HTML Pin
vho12329-Apr-10 22:46
vho12329-Apr-10 22:46 
AnswerRe: XSLT to HTML Pin
Stuart Dootson6-May-10 2:00
professionalStuart Dootson6-May-10 2:00 
QuestionCan anyone give me a hand with this? Pin
ajweber27-Apr-10 20:20
ajweber27-Apr-10 20:20 
AnswerRe: Can anyone give me a hand with this? Pin
Not Active28-Apr-10 1:54
mentorNot Active28-Apr-10 1:54 
GeneralRe: Can anyone give me a hand with this? Pin
ajweber28-Apr-10 6:59
ajweber28-Apr-10 6:59 
GeneralRe: Can anyone give me a hand with this? Pin
Not Active28-Apr-10 7:10
mentorNot Active28-Apr-10 7:10 
GeneralRe: Can anyone give me a hand with this? Pin
ajweber28-Apr-10 7:17
ajweber28-Apr-10 7:17 
GeneralRe: Can anyone give me a hand with this? Pin
Not Active28-Apr-10 7:31
mentorNot Active28-Apr-10 7:31 
GeneralRe: Can anyone give me a hand with this? Pin
ajweber28-Apr-10 7:52
ajweber28-Apr-10 7:52 
QuestionDesperate seeking answer to simple problem Pin
Axiom70m27-Apr-10 6:45
Axiom70m27-Apr-10 6:45 
AnswerRe: Desperate seeking answer to simple problem Pin
Not Active27-Apr-10 7:57
mentorNot Active27-Apr-10 7:57 
GeneralRe: Desperate seeking answer to simple problem [modified] Pin
Axiom70m27-Apr-10 8:47
Axiom70m27-Apr-10 8:47 
GeneralRe: Desperate seeking answer to simple problem Pin
Not Active27-Apr-10 10:41
mentorNot Active27-Apr-10 10:41 
GeneralRe: Desperate seeking answer to simple problem [modified] Pin
Axiom70m27-Apr-10 22:52
Axiom70m27-Apr-10 22:52 
GeneralRe: Desperate seeking answer to simple problem Pin
Not Active28-Apr-10 1:52
mentorNot Active28-Apr-10 1:52 
GeneralRe: Desperate seeking answer to simple problem Pin
Axiom70m28-Apr-10 3:00
Axiom70m28-Apr-10 3:00 
GeneralRe: Desperate seeking answer to simple problem Pin
Axiom70m29-Apr-10 1:16
Axiom70m29-Apr-10 1:16 
QuestionHow ti create sitemap in xml? Pin
JMecier25-Apr-10 1:59
JMecier25-Apr-10 1:59 
AnswerRe: How ti create sitemap in xml? Pin
User 171649225-Apr-10 2:11
professionalUser 171649225-Apr-10 2:11 
GeneralRe: How ti create sitemap in xml? Pin
JMecier27-Apr-10 4:57
JMecier27-Apr-10 4:57 

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.