If you use System.Xml.XmlReader in the .NET Framework to read XML data, the blank characters in the attribute values are not normalized.
Normalization of blank characters in attribute values is as follows:
"foo
bar"
<"foo bar"
"foo bar"
<"foo bar"
Note:
I can normalize it myself when I use XmlReader directly, but I can't think of a good way to normalize it when I pass XmlReader to XmlSerializer for de-serialize it.
Is there any other way to avoid this problem other than the following two methods?
Action (image) that would be good for both processing and implementation efficiency if:
using(var xmlReader=XmlReader.Create(streamReader,xmlSettings))
{
// If you could do something like Ruby's unique method...
public override string xmlReader.Value
{
get{
var value = transferred to .Value
if(NodeType==XmlNodeType.Attribute)
{
//value normalization
}
return value;
}
}
t=(T)xmlSerializer.Deserialize(xmlReader);
}
Link to
At first, a character reference such as ሴ
means adding the character it indicates to an empty box.Adding to a normalized value means adding characters to an empty box, meaning that characters written in a character reference are treated as characters and are no longer treated.In that respect, the results are clearly different from those described later.You may have a technique to write characters as references.
is described (especially the last sentence).Of course, Extensible Markup Language (XML) 1.0 (Fifth Edition), 3.3.3 Attribute-Value Normalization is also
and 

expands to \r\n
and is not replaced by under normal behavior?
In fact,
<element attribute="a
b
c"></element>
The value of attribute
in was ab\r\nc
.
The real problem is that "foo bar"
does not become "foo bar"
(blank before and after deletion and blank compression in the middle).
This is exactly what the link says.
The first half described the conditions under which this regulation is invoked.If DTD is not used, attributes should be treated as CDATA types, so this is a meaningful provision mainly when DTD describes the type of attributes.
If you specify the attribute NMTOKENS
in DTD, it will be normalized to the specification, and if it is unspecified or CDATA, it will not be converted to the specification.In addition, XmlReaderSettings.DtdProcessing
must be set to DtdProcessing.Parse
to handle DTD.
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
public class test
{
[XmlAttribute]
public string Nmtokens {get;set;}
[XmlAttribute]
public string Cdata {get;set;}
public stringElem {get;set;}
public static void Main()
{
varxml=@"<!DOCTYPE Test[
<!ELEMENT TEST (Elem)>
<!ATTLIST Test Nmtokens NMTOKENS #REQUIRED Cdata CDATA #REQUIRED>
<!ELEMENTEM(#PCDATA)>
] >
<Test Nmtokens='foo bar'Cdata='foo bar'>
<Elem>foo bar</Elem>
</Test>
";
var reader = XmlReader.Create (new StringReader (xml), new XmlReaderSettings {DtdProcessing=DtdProcessing.Parse});
vartest=(Test) new XmlSerializer(typeof(Test)) .Deserialize(reader);
Console.WriteLine("Nmtokens=<{0}>, Cdata=<{1}>, Elem=<{2}>", test.Nmtokens, test.Cdata, test.Elem);
// Nmtokens=<foo bar>, Cdata=<foo bar>, Elem=<foo bar>
}
}
Although the entire question statement states that the translation is in accordance with the specification, such as "Blank characters in attribute values are not normalized", it should be recognized that you want an out-of-spec special translation.
You can inherit the XmlTextReader
and Value
property only override if you do not want to do asynchronous processing.
597 GDB gets version error when attempting to debug with the Presense SDK (IDE)
567 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
577 PHP ssh2_scp_send fails to send files as intended
885 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.