Comments (12)
Fully agree, @binki, thanks.
Currently, illegal characters throw e.g.
System.ArgumentException : '\ufffe', hexadecimal value 0xFFFE, is an invalid character.
in YAXSerializer
public string Serialize(object obj)
{
// System.Xml.Linq.XNode.ToString()
return SerializeXDocument(obj).ToString();
}
@304NotModified @NKnusperer - What does this mean:
- Issue #2 (comment) is not bug, but the consequence of following the XML specification
- The exception thrown is correct
- I like @binki's suggestion to offer
Convert.ToBase64String()
by creating e.g.YAXBase64StringAttribute
- In case of (3) the
BUG
label should becomeENHANCEMENT
, otherwise the issue should be closed
What do you think?
from yaxlib.
It’s impossible to safely serialize .net strings as-is in XML. Even XML-1.1, which allows control characters, doesn’t support the null character (\0
). And using XML-1.1 isn’t recommended.
It’s OK to serialize your strings directly as XML content only if your data model itself disallows control characters in content. I.e., you should be throwing errors before trying to serialize to XML if you are going to do this because you should just overall not support them if serializing your strings to XML in this way is a requirement.
If you need to support transporting unconstrained .net string data via XML, your only option is to encode it in something protective like base64 as part of serializing.
The right thing for YAXLib to do is to make sure it throws when asked to serialize characters in an unsupported way.
from yaxlib.
This is related to #8. The current algorithm is a bit naïve and should probably rather be based on the definition of an XML Name from the XML specification.
from yaxlib.
Actually it's not related to XML-element or XML-attribute names. This is related to their content, which cannot contain those control characters.
from yaxlib.
Ah, I see. Then the definition Text in the XML specification might be of help.
from yaxlib.
Is it verified already that we don't follow the definition Text in the XML specification?
"Control characters" seems to be a too general description?
from yaxlib.
@304NotModified
Looks like there's a rather simple way to de/serialize string
fields/properties as CData
or Base64
-encoded.
I'm considering a YAXStringEmbeddingAttribute
which allows for StringEmbedding.None
| StringEmbedding.CData
| StringEmbedding.Base64
.
What do you think? (Also not sure about a good term for this attribute and enum)
from yaxlib.
Looks like there's a rather simple way to de/serialize
string
fields/properties asCData
orBase64
-encoded.
I'm considering aYAXStringEmbeddingAttribute
which allows forStringEmbedding.None
|StringEmbedding.CData
|StringEmbedding.Base64
.
Sounds good!
What do you think? (Also not sure about a good term for this attribute and enum)
Maybe YAXStringEncodingAttribute? Or YAxTextEncodingAttribute or just YAXEncodingAttribute?
This is an older story, but I would expect there should be way to just remove the illigal characters like \u0003. I know it gives headaches also in Sql Server. See docs
from yaxlib.
there should be way to just remove the illegal characters like \u0003
Agree. In it's simplest form all values would have to undergo a RegEx.Replace
or maybe better stripped like
var input = "abc\u0003def";
var validXmlString = new string(input.Where(XmlConvert.IsXmlChar).ToArray())
If we're lucky, all values are anyway retrieved using XMLUtils.ToXmlValue(this object? self, CultureInfo culture)
and the clean-up could be added there ;-) Then, maybe we could introduce YAXSerializationOptions.StripInvalidXmlChars
or alike.
But then this is a new issue?
[Edit]
Or use the new CData
also as the way to strip-off invalid characters?
from yaxlib.
YAXSerializationOptions.StripInvalidXmlChars
I like that one :)
from yaxlib.
Implementing YAXTextEmbeddingAttribute
is done. YAXTextEmbedding.CData
will always strip invalid chars. If this is undesired, the alternative YAXTextEmbedding.Base64
is there.
Will post a new PR after #203 is merged.
from yaxlib.
Resolved with release v4.0.0
from yaxlib.
Related Issues (20)
- Dictionary serialization incorrect when publishing to single file HOT 4
- Generic deserialization methods should not hide base methods with 'new', e.g. with a generic base class HOT 1
- Possible regression caused by PR #183 HOT 9
- Extend tests to cover YAXSerializer and YAXSerializer<T> HOT 2
- Extend caching and pooling for better performance HOT 10
- Split IYAXSerializer<T> to IYAXSerializer<T> and IYAXDeserializer<T> HOT 7
- Make Exception a KnownType HOT 4
- All public members of YAXSerializer (generic/non-generic) should be fully covered by unit tests HOT 1
- How serialize a list as an attribute HOT 7
- Extend SerializationContext for pre-processing in ICustomSerializer and IKnownType
- Add unit tests for YAXCollectionItemTypeAttribute and YAXElementForAttribute
- Add YAXSerializationOptions.StripInvalidXmlChars HOT 3
- Structs are not serialized correctly HOT 3
- Update docs for new v4 features
- Multiple Elements with Same Name? How to Deserialize?
- Add support for DateOnly and TimeOnly types
- Is it possible deserialize to property by attribute name and inner xml with YAXLib?
- Serializing/Deserializing ValueTuples HOT 1
- Serialize not filtering properties correctly in .NET Standard HOT 6
- Serialized strings that use the stringbuilder pool throw when the string's length is > 1024 (DefaultStringBuilderCapacity).
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yaxlib.