Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SOAP - removing specific Headers 1

Status
Not open for further replies.

vikaskalra

Technical User
Aug 12, 2002
41
GB
Hi !

I have a SOAP - XML string :-

<SOAP-ENV:Envelope xmlns:xsi=&quot; xmlns:xsd=&quot; xmlns:SOAP-ENC=&quot; xmlns:SOAP-ENV=&quot; xmlns:clr=&quot; SOAP-ENV:encodingStyle=&quot;<SOAP-ENV:Body>
<a1:iStruct id=&quot;ref-1&quot; xmlns:a1=&quot; <CustomerID id=&quot;ref-3&quot;>WOLZA</CustomerID>
<CompanyName id=&quot;ref-4&quot;>Wolski Zajazd</CompanyName>
<ContactName id=&quot;ref-5&quot;>Zbyszek Piestrzeniewicz</ContactName>
<ContactTitle id=&quot;ref-6&quot;>Owner</ContactTitle>
<Address id=&quot;ref-7&quot;>ul. Filtrowa 68</Address>
<City id=&quot;ref-8&quot;>Warszawa</City>
<Region id=&quot;ref-9&quot;>Test Region</Region>
<PostalCode id=&quot;ref-10&quot;>01-012</PostalCode>
<Country id=&quot;ref-11&quot;>Poland</Country>
<Phone id=&quot;ref-12&quot;>(26) 642-7012</Phone>
<Fax id=&quot;ref-13&quot;>(26) 642-7012</Fax>
</a1:iStruct>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Now I want to remove the headers i.e. <SOAP-ENV:Envelope> and <SOAP-ENV:Body> tags, as I want to extract the other data inside these tags. In XML, I was able to do this by using DocElement.SelectNodes, and find the exact node and then extract the content Using OuterXml.

Is there any way I can do this in SOAP ?

Thanx in advance for the help,
Vikas
 
I don't quite understand your question as SOAP documents are XML documents, so there isn't &quot;another&quot; way to access the data. You just access the content of the element you are interested in. If I misunderstood please clarify.

Regards,
John
 
Hi John !

Actually I don't have to extract the Texts of the nodes. I need to Display only the following part as it is with the Tags:-

<CustomerID id=&quot;ref-3&quot;>WOLZA</CustomerID>
<CompanyName id=&quot;ref-4&quot;>Wolski Zajazd</CompanyName>
<ContactName id=&quot;ref-5&quot;>Zbyszek Piestrzeniewicz</ContactName>
<ContactTitle id=&quot;ref-6&quot;>Owner</ContactTitle>
<Address id=&quot;ref-7&quot;>ul. Filtrowa 68</Address>
<City id=&quot;ref-8&quot;>Warszawa</City>
<Region id=&quot;ref-9&quot;>Test Region</Region>
<PostalCode id=&quot;ref-10&quot;>01-012</PostalCode>
<Country id=&quot;ref-11&quot;>Poland</Country>
<Phone id=&quot;ref-12&quot;>(26) 642-7012</Phone>
<Fax id=&quot;ref-13&quot;>(26) 642-7012</Fax>

What I want to do is remove all the Header Tags i.e the following ones :-

<SOAP-ENV:Envelope xmlns:xsi=&quot; xmlns:xsd=&quot; xmlns:SOAP-ENC=&quot; xmlns:SOAP-ENV=&quot; xmlns:clr=&quot; SOAP-ENV:encodingStyle=&quot;<SOAP-ENV:Body>

Regards n Thanks,
Vikas
 
Are you actually trying to create exactly what you said, which is not well-formed XML, or a real XML document with a single top-level element? In either case, you could use XSLT to transform the SOAP document to what you want.

Regards,
John
 
The complete story is - When a user accesses a page, I retrieve all the information, place it in a Structure, pass this Struct to the Presentation Layer from the Business Logic Layer.

The user does some modification and saves it to the DB, in this process I get a New Structure. Now behind the scenes, I Serialize both the Original and the New Structure and save it to Database (Binary Format) as part of User activity.

Due to some reasons, I am not storing the Serialized data in XML/ SOAP format in the database.

Now in the Auditing Module, this activity gets listed, when I go for details of this Activity, I fetch both the Old and the New Struct, deserialize it and again Serialize it, the options I have either to go for SOAP / XML.

In case of XML, I get all the control, I am able to remove the parent tags, and show the content as it is, which I am not able to do in case of SOAP. Actually applying XSLT is the best thing, but in my case it is not viable as I have 25 different modules and more than 17 different structures, so in that case I will have to make different XSLT for all the 17 different structures. So we decided against going for XSLT and showing XML / SOAP data as it is.

See in the following Example :

Private Function FormatXml(ByVal srcString As String) As String
Dim _StringBuilder As New StringBuilder
Dim _AttrColl As XmlAttributeCollection
Dim _XmlTxtReader As XmlTextReader
Dim _XmlDoc As New XmlDocument
Dim _DocElement As XmlNode
Dim _ResultNodes As XmlNodeList
Dim _XmlNode As XmlNode

_XmlTxtReader = New XmlTextReader(New StringReader(srcString))
_XmlDoc.Load(_XmlTxtReader)
_DocElement = _XmlDoc.DocumentElement
_AttrColl = _DocElement.Attributes
_AttrColl.Remove(_AttrColl.ItemOf(&quot;xmlns:xsd&quot;))
_AttrColl.Remove(_AttrColl.ItemOf(&quot;xmlns:xsi&quot;))
_ResultNodes = _DocElement.SelectNodes(&quot;/MyStruct/node()&quot;)
For Each _XmlNode In _ResultNodes
_StringBuilder.Append(_XmlNode.OuterXml)
Next _XmlNode
FormatXml = _StringBuilder.ToString
End Function

Here I am able to remove any Attributes and the XML tags that appear at the Starting of the Document, as well as Structure Tags if need be, as a result I get Child Nodes only. All I want to know is such a thing possible with SOAP ? if yes then how do I access the Nodes ? I mean what do I specify in :-

_ResultNodes = _DocElement.SelectNodes(&quot;/MyStruct/node()&quot;)

Regards,
Vikas
 
Hey there, sorry it took so long to respond, I was quite busy at work today. Doesn't the following XSLT stylesheet do what you want?

Code:
<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; ?>
<xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;[URL unfurl="true"]http://www.w3.org/1999/XSL/Transform&quot;[/URL] 
  xmlns:SOAP-ENV=&quot;[URL unfurl="true"]http://schemas.xmlsoap.org/soap/envelope/&quot;>[/URL]
	<xsl:strip-space elements=&quot;*&quot;/>
	<xsl:output omit-xml-declaration=&quot;yes&quot;/>
	<xsl:template match=&quot;/SOAP-ENV:Envelope/SOAP-ENV:Body/*[1]&quot;>
			<xsl:apply-templates mode=&quot;deepcopy&quot;/>
	</xsl:template>
	<xsl:template match=&quot;@*|node()&quot; mode=&quot;deepcopy&quot;>
		<xsl:copy>
			<xsl:apply-templates select=&quot;@*|node()&quot; mode=&quot;deepcopy&quot;/>
		</xsl:copy>
		<xsl:value-of select=&quot;string(&quot;
&quot;)&quot;/>
	</xsl:template>	
</xsl:stylesheet>

Here is an output of the transformed xml for your sample:

<CustomerID id=&quot;ref-3&quot;>
WOLZA
</CustomerID>
<CompanyName id=&quot;ref-4&quot;>
Wolski Zajazd
</CompanyName>
<ContactName id=&quot;ref-5&quot;>
Zbyszek Piestrzeniewicz
</ContactName>
<ContactTitle id=&quot;ref-6&quot;>
Owner
</ContactTitle>
<Address id=&quot;ref-7&quot;>
ul. Filtrowa 68
</Address>
<City id=&quot;ref-8&quot;>
Warszawa
</City>
<Region id=&quot;ref-9&quot;>
Test Region
</Region>
<PostalCode id=&quot;ref-10&quot;>
01-012
</PostalCode>
<Country id=&quot;ref-11&quot;>
Poland
</Country>
<Phone id=&quot;ref-12&quot;>
(26) 642-7012
</Phone>
<Fax id=&quot;ref-13&quot;>
(26) 642-7012
</Fax>

Regards,
John
 
BTW, the
Code:
<xsl:value-of select=&quot;string(&quot;
&quot;)&quot;/>

should be

Code:
<xsl:value-of select=&quot;string(&quot;&#10;&quot;)&quot;/>

Sorry about the double post, didn't realize part of it was seen as valid html (wouldn't think [code/] would change anything).

Regards,
John
 
And, third times a charm:

Code:
<xsl:value-of select=&quot;string(&quot;
&quot;)&quot;/>
should BE
Code:
<xsl:value-of select=&quot;string(&amp;quot;&amp;#10;&amp;quot;)&quot;/>

Regards,
John
 
Hi!

Thanks for your inputs, I will try this thing out.

Regards,
Vikas
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top