EldoS | Feel safer!

Software components for data protection, secure storage and transfer

XML escape characters in attributes .NET

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#16489
Posted: 05/23/2011 08:40:01
by Matthias Pr (Basic support level)
Joined: 05/23/2011
Posts: 3

Hi,

we're trying to parse some XML from a string which has some escaped characters in it. For testing purposes I wrote the following code which could illustrate the problem.

Code
TElXMLDOMDocument xml = new TElXMLDOMDocument();

MemoryStream m = new MemoryStream();
StreamWriter s;
            
s = new System.IO.StreamWriter(m, new System.Text.ASCIIEncoding());

s.Write("<?xml version='1.0' ?>\n<ROOT a='Hello&#xA;&#xD;World'></ROOT>");
s.Flush();
m.Seek(0, SeekOrigin.Begin);

xml.LoadFromStream(m);

TElXMLDOMAttr attr = (TElXMLDOMAttr) xml.DocumentElement.Attributes.get_Item(0);

            
Console.WriteLine(attr.NodeValue);
Console.ReadKey();


Unfortunately the program does not seem to be able to properly handle the escaped characters. Instead of a line break the program output is just

Code
Hello&;&;World


I have already tried different encodings (both in the XML header and as a replacement for the ASCIIEncoding). (This is probably correct anyway as I can inspect attr.OuterXML with the value : "a='Hello World'")

Is there a different way to get the value of the attribute?


.NET 4.0
SecureBlackBox Version 8.2.195.39707
SecureBlackBox XML 8.2.195.39773
Visual Studio 2010 SP1
#16490
Posted: 05/23/2011 09:53:34
by Dmytro Bogatskyy (EldoS Corp.)

There is a bug in a getter of ElXMLDOMAttr.NodeValue/Value property in processing numeric character entities. It is fixed for the next build. Unfortunately, there is no simple way to output a correct attribute value without NodeValue property, you will need to process all attribute childs (for text nodes and entities) and build a string value. If you need a sample let me know.
Thank you for pointing this.
#16587
Posted: 06/08/2011 07:32:57
by Matthias Pr (Basic support level)
Joined: 05/23/2011
Posts: 3

Just installed the new version, despite the change notes I'm still having problems with NodeValue - this time seen in the VCL version...

Code
var s : TMemoryStream;
    xml : TElXMLDOMDocument;
    attr : TElXMLDOMAttr;

begin
  try
    s := TMemoryStream.Create;
    s.LoadFromFile('c:\mp\test.xml');
    s.Seek(0,soBeginning);

    xml := TElXMLDOMDocument.Create;
    xml.LoadFromStream(s);

    attr := TElXMLDOMAttr(xml.DocumentElement.Attributes.Item[0]);

    Writeln(attr.NodeValue);
    ReadLn;

  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Output:

Code
Hello&;&;World


SecureBlackbox - version 9.0.202
Embarcadero® Delphi® XE Version 15.0.3890.34076
#16589
Posted: 06/08/2011 08:19:26
by Dmytro Bogatskyy (EldoS Corp.)

That's strange.
Possible some old dcu's are left.
What does the following code return:
Code
  WriteLn(SBUtils.SBB_VERSION_NUMBER);
#16590
Posted: 06/08/2011 08:23:34
by Matthias Pr (Basic support level)
Joined: 05/23/2011
Posts: 3

9.0.201.0
#16596
Posted: 06/08/2011 12:10:16
by Dmytro Bogatskyy (EldoS Corp.)

Unfortunately, the version of SecureBlackbox package for Delphi 2009, 2010 and XE is left 9.0.201, due to a bug in the build process.
The new version (203 build) is expected at this weekends, so we don't plan to replace a current package at the moment, sorry.
Thank you for pointing this.
#16643
Posted: 06/12/2011 08:41:57
by Eugene Mayevski (EldoS Corp.)

JFYI: new build is available on the site.


Sincerely yours
Eugene Mayevski
Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.

Reply

Statistics

Topic viewed 1192 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!