Encoding space character in XML name
The XML isn't broken, but it's representing names using a private convention for escaping disallowed characters. The XML parser won't understand this convention, it's up to the receiving application to interpret it.
How to put space character into a string name in XML?
to use white space in xml as string use
. XML won't take white space as it is. it will trim the white space before setting it. So use
instead of single white space
Allowed symbols in XML element name
Right: Letter, digit, hyphen, underscore and period.
One may use any Unicode letter.
And of course one may prefix the names with name space + colon.
Parsing XML with spaces in element names
Unfortunately, the text returned by your library is not a well-formed XML, so you cannot use an XML parser to parse it. The spaces in the tags are only part of the problem; there are other issues, for example, the absence of the "root" tag.
Fortunately, a single-level language is trivial enough to be matched with regular expressions. Regex-based "parsers" would be an awful choice for real XML, but this language is not real, so you could use regex at least as a workaround:
Regex rx = new Regex("<([^>\n]*)>(.*?)</(\\1)>");
var m = rx.Match(text);
while (m.Success) {
Console.WriteLine("{0}='{1}'", m.Groups[1], m.Groups[2]);
m = m.NextMatch();
}
The idea behind this approach is to find strings with "opening tags" that match "closing tags" with a slash.
Here is a demo, it produces the following output for your input:
live key='test'
not live='test'
Test='hello'
How do I add a space in an XML schema element?
You can't. That would go against the XML specification. The space character is used as a delimiter in XML and has special meaning. It cannot appear in element names.
Think about the resulting element that you would be defining with that declaration:
<Last Name attribute1="value" attribute2="value">Contents</Last Name>
That doesn't look anything like XML and would be rejected by any XML parser.
Related Topics
Convert Datetime to Julian Date in C# (Tooadate Safe)
How to Find the Mode in Array C#
Parsing Performance (If, Tryparse, Try-Catch)
Generic C# Code and the Plus Operator
C# Winforms Errorprovider Control
C# Printing Problem (Richtextbox)
Jquery Ajax Call to an ASP.NET Webmethod
Regex Split String But Keep Separators
Exception Using Copytodatatable with "New {..}" Linq Query
What Difference Is There Between Webclient and Httpwebrequest Classes in .Net
How to Force C# .Net App to Run Only One Instance in Windows
View Post Request Body in Application Insights
How to Pass Parameters to Activator.Createinstance<T>()
How to Ignore a Property When Serializing Using the Datacontractserializer
String.Tolower() and String.Tolowerinvariant()
How to See the Raw Http Request That the Httpwebrequest Class Sends