Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Suppress Xmlns in InnerXML / Rename an XML node in DOM

Suppress Xmlns in InnerXML / Rename an XML node in DOM

Scheduled Pinned Locked Moved XML / XSL
xmlhelpquestionhtmldatabase
2 Posts 1 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Ger Hayden
    wrote on last edited by
    #1

    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("

    G 1 Reply Last reply
    0
    • G Ger Hayden

      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("

      G Offline
      G Offline
      Ger Hayden
      wrote on last edited by
      #2

      ... I avoided the need to do either by using OuterXML: XmlNode ^TmpNode; XmlNode ^IE315_Node; XmlNode ^IE313_Node; String^ tmpstr; switch (current_message) { case (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); } tmpstr = IE315_Node->OuterXml->ToString(); tmpstr = tmpstr->Replace("EntrySummaryDeclaration", "EntrySummaryDeclarationAmendment"); tmpstr = tmpstr->Replace("IE315", "IE313"); doc->RemoveChild(IE315_Node); doc->LoadXml(tmpstr); current_message = MessageType::IE313; Convert->Text = "Con&vert to IE315"; ReferenceNumber->Text = ""; ReferenceNumber->Enabled = true; break; }

      Ger

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups