Click here to Skip to main content
14,661,504 members
Home » Discussions » XML / XSL
   

XML / XSL

 
GeneralRe: writing to xml file Pin
Farraj9-Jun-10 8:42
MemberFarraj9-Jun-10 8:42 
QuestionHow to access xml file simultaneously at runtime Pin
Raghu_M21-May-10 5:12
MemberRaghu_M21-May-10 5:12 
QuestionUsing SAX and PHP Pin
vho12318-May-10 20:22
Membervho12318-May-10 20:22 
QuestionXSLT and asp.NET mixture Pin
ceviz16-May-10 13:02
Memberceviz16-May-10 13:02 
AnswerRe: XSLT and asp.NET mixture Pin
Not Active16-May-10 17:08
mentorNot Active16-May-10 17:08 
AnswerRe: XSLT and asp.NET mixture Pin
Atwind27-Jun-10 23:42
MemberAtwind27-Jun-10 23:42 
Questionlanguage localization using XML in VC++ (MFC) Pin
punyah20108-May-10 9:03
Memberpunyah20108-May-10 9:03 
QuestionSuppress Xmlns in InnerXML / Rename an XML node in DOM Pin
Ger Hayden6-May-10 11:37
MemberGer Hayden6-May-10 11: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 7:24
MemberGer Hayden8-May-10 7:24 
QuestionParsing RSS Pin
Aljaz1116-May-10 3:37
MemberAljaz1116-May-10 3:37 
AnswerRe: Parsing RSS Pin
Stuart Dootson6-May-10 23:24
professionalStuart Dootson6-May-10 23:24 
QuestionXSLT to HTML Pin
vho12329-Apr-10 21:46
Membervho12329-Apr-10 21:46 
AnswerRe: XSLT to HTML Pin
Stuart Dootson6-May-10 1:00
professionalStuart Dootson6-May-10 1:00 
QuestionCan anyone give me a hand with this? Pin
ajweber27-Apr-10 19:20
Memberajweber27-Apr-10 19:20 
AnswerRe: Can anyone give me a hand with this? Pin
Not Active28-Apr-10 0:54
mentorNot Active28-Apr-10 0:54 
GeneralRe: Can anyone give me a hand with this? Pin
ajweber28-Apr-10 5:59
Memberajweber28-Apr-10 5:59 
GeneralRe: Can anyone give me a hand with this? Pin
Not Active28-Apr-10 6:10
mentorNot Active28-Apr-10 6:10 
GeneralRe: Can anyone give me a hand with this? Pin
ajweber28-Apr-10 6:17
Memberajweber28-Apr-10 6:17 
GeneralRe: Can anyone give me a hand with this? Pin
Not Active28-Apr-10 6:31
mentorNot Active28-Apr-10 6:31 
GeneralRe: Can anyone give me a hand with this? Pin
ajweber28-Apr-10 6:52
Memberajweber28-Apr-10 6:52 
QuestionDesperate seeking answer to simple problem Pin
Axiom70m27-Apr-10 5:45
MemberAxiom70m27-Apr-10 5:45 
AnswerRe: Desperate seeking answer to simple problem Pin
Not Active27-Apr-10 6:57
mentorNot Active27-Apr-10 6:57 
GeneralRe: Desperate seeking answer to simple problem [modified] Pin
Axiom70m27-Apr-10 7:47
MemberAxiom70m27-Apr-10 7:47 
GeneralRe: Desperate seeking answer to simple problem Pin
Not Active27-Apr-10 9:41
mentorNot Active27-Apr-10 9:41 
GeneralRe: Desperate seeking answer to simple problem [modified] Pin
Axiom70m27-Apr-10 21:52
MemberAxiom70m27-Apr-10 21:52 

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.