Solved

XML encoding < and >

Posted on 2004-08-24
2
7,848 Views
Last Modified: 2012-05-05
I have and XML document that has been built up as a string (using VBScript) see below

Dim XMLIn
XMLIn = "<?xml version=""1.0"" encoding=""Windows-1252""?>" & _
                "<Query xmlns:xsd=""http://www.w3.org/2000/10/XMLSchema-instance"" xsd:noNamespaceSchemaLocation=""INVQRY.XSD"">" & _
      "<Key>" & _
      "<StockCode>BCS100</StockCode>" & _
      "</Key>" & _
      "</Query>"

What I need to do is convert this so that all the "<" and ">" are replaced by &lt; and &gt;
The reason for this is that this string needs to passed in a SOAP message to a webservice. If the < and > are present then SOAP tries to interpret the XML as commands to SOAP and fails.

Can anyone recommend a control that would encode the string for me?

Regards

Andy
0
Comment
Question by:ieg
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 250 total points
ID: 11880626
Are you able to use Replace() ?

Something like:

    XMLIn = Replace(XMLIn, "<", "&lt;")
    XMLIn = Replace(XMLIn, ">", &gt;")


0
 

Author Comment

by:ieg
ID: 11881738
Carl,
This worked a treat.

Thanks very much

Andy
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now