cancel
Showing results for 
Search instead for 
Did you mean: 

'&' in Value-node of GetObjectKeyBySingleValue request doesn't work

Former Member
0 Kudos

I am developing a web service that uses the DI Server for accessing the SBO database. I use a GetObjectBySingleValue request to get all DocEntries from oPurchaseOrders (OPOR) that match to a suppliername:


 sCmd = "<?xml version=""1.0"" encoding=""UTF-16""?>"
 sCmd += "<env:Envelope xmlns:env=""http://schemas.xmlsoap.org/soap/envelope/"">"
 sCmd += "<env:Header><SessionID>" & SessionID & "</SessionID></env:Header>"
 sCmd += "<env:Body><dis:GetObjectKeyBySingleValue xmlns:dis=""http://www.sap.com/SBO/DIS"">"
 sCmd += "<ObjNum>oPurchaseOrders</ObjNum>"
 sCmd += "<PropName>CardName</PropName>"
 sCmd += "<Value>" & SupplierName & "</Value>"
 sCmd += "<Condition>bqc_Equal</Condition>"
 sCmd += "</dis:GetObjectKeyBySingleValue></env:Body></env:Envelope>"

The request works for most suppliernames, but when I try to get the docEntries for the supplier "Clothes & More", I'm getting an error message:


env: Sender  Invalid XML  Expected entity name for reference

I think it doesn't work because of the '&' sign, because this differs from other suppliernames.

Does someone know, how to get this work?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Try replacing & with &amp;

If that doesn't work, you can allways make your xml through DOM or something instead of just writing Strings, to ensure that it will be well-formatted.

Former Member
0 Kudos

thanks a lot. it works with &amp; . but I think '&' is not the only sign that can cause problems, right? do you have a list of all signs I have to consider?

Former Member
0 Kudos

or better, does someone know how to format a string to a string that is conform to xml in .NET? for example that "&" is replaced with "&amp;" .

Former Member
0 Kudos

If you make your xml as a .Net XmlDocument, special characters should be parsed correctly automatically.

For example, start building your xml something like this

XmlDocument doc = new XmlDocument();

XmlElement e = doc.CreateElement("env:Envelope");

e.SetAttribute("xmlns:env","http://schemas.xmlsoap.org/soap/envelope/");

//...

Former Member
0 Kudos

I tried the following:


 Dim tempXml As New Xml.XmlDocument
 Dim xmle As Xml.XmlElement = tempXml.CreateElement("temp")
 xmle.SetAttribute("value", "Clothes & More")
 dim str as string = xmle.GetAttribute("value")

but str = "Clothes & More" and not "Clothes &amp; More" . I cannot believe that there is no simple way to encode such as string?!?

Former Member
0 Kudos

What I ment was to create your whole xml-document by adding nodes to the xmldocument, and then call the WriteContentTo() method.

All characters will then be parsed correctly.

Here is a small example that writes to a file, tmp.txt. Sorry it's in c#

XmlDocument doc = new XmlDocument();

XmlElement e;

e = doc.CreateElement("Value"); doc.AppendChild(e);

e.AppendChild(doc.CreateTextNode("Test & Test2"));

XmlTextWriter writer = new XmlTextWriter(new FileStream("tmp.txt",FileMode.Create),System.Text.Encoding.Unicode);

writer.Formatting = System.Xml.Formatting.Indented;

writer.WriteStartDocument();

doc.WriteContentTo(writer);

writer.Flush();

Former Member
0 Kudos

thanks a lot. this works. I just wrote a function that loads an xml document from a string and returns an encoded string. Just the way I want it.

Answers (0)