Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 6th, 2006, 07:41 AM
Authorized User
 
Join Date: Oct 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to monuindia2002
Default Appending to the middle of a file

Hi,
I have an xml file like this

<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>


i want to append a tag between envelope and body tag.
how do i append that.
Can any body help me in this.

Thanks


Mahesh
__________________
Mahesh
 
Old March 6th, 2006, 07:57 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

There are two main options, open the document using the DOM and use the appendChild method, or use an XSL transform?
Which method do you have in mind and what platform are you using?

--

Joe (Microsoft MVP - XML)
 
Old March 7th, 2006, 02:32 AM
Authorized User
 
Join Date: Oct 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to monuindia2002
Default

Thanks Joe

I am using .net and I will do with DOM.

Thanks
Mahesh

Mahesh
 
Old March 7th, 2006, 05:14 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

In C#
Code:
using System;
using System.Xml;

namespace UseXmlDocument
{
  class Program
  {
    static void Main(string[] args)
    {
      XmlDocument doc = new XmlDocument();
      doc.Load(@"<path to XML here>");
      XmlNamespaceManager nsManager = new XmlNamespaceManager(doc.NameTable);
      string soapNs = @"http://schemas.xmlsoap.org/soap/envelope/";
      nsManager.AddNamespace("SOAP-ENV", soapNs);
      XmlElement soapHeader = doc.CreateElement("SOAP-ENV", "Header", soapNs);
      XmlNode soapEnvelope = doc.SelectSingleNode("SOAP-ENV:Envelope", nsManager);
      XmlNode soapBody = doc.SelectSingleNode("SOAP-ENV:Envelope/SOAP-ENV:Body", nsManager);
      soapEnvelope.InsertBefore(soapHeader, soapBody);
      Console.Write(doc.OuterXml);
      Console.ReadLine();
    }
  }
}
--

Joe (Microsoft MVP - XML)
 
Old March 8th, 2006, 05:21 AM
Authorized User
 
Join Date: Oct 2005
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to monuindia2002
Default

Thank you verymuch Joe

It Worked for me

Regards
Mahesh

Mahesh





Similar Threads
Thread Thread Starter Forum Replies Last Post
Appending child nodes to a RDF/OWL file using xslt sesath XSLT 2 May 10th, 2007 04:37 AM
Repeating image in middle of a page ychange Javascript How-To 1 March 11th, 2007 03:45 AM
Circular appending LOG file eelisMX Pro VB.NET 2002/2003 4 March 1st, 2005 06:30 AM
Need to grab middle data from field datagram Classic ASP Databases 4 December 16th, 2004 12:37 PM
How to Insert additional column in the Middle of a ramk_1978 BOOK: Beginning ASP 3.0 0 November 6th, 2004 09:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.