views:

232

answers:

3

Hello everyone,

I need to send some XML element to some other services and I want to ensure my XML file is of elegant format so that other people could use their XML parser to parse the XML file.

For such kinds of XML file, is it elegant format, breaking any rules of XML? Not sure whether &#x4 is valid XML character sequences in .Net/C#?

I am confused about whether strings starts with $#x are all valid? If not all of them are valid, any ways to filter them out?

I am using VSTS 2008 + C# + .Net 3.5.

<?xml version="1.0" encoding="utf-8"?>
<Text>&#x4;</Text>

thanks in advance, George

+7  A: 

No. Character references must be terminated with semi-colons.

Update: Given that syntax error in the question has been corrected, see http://www.w3.org/TR/xml/#dt-charref for a description of what values are acceptable.

Frankly, I'd stick to UTF-8 for everything except ", <, > and &. It makes the XML itself more readable.

David Dorward
So it should be `<Text></Text>`
voyager
Sorry it is my typo, I have corrected it, it should be ends with ; in my input. Are they valid XML strings which could be used in XML element values?
George2
Thanks for your update. For .Net are there any existing methods or easy solution to filter out such characters?
George2
+5  A: 

Use XML Validator. It shows the following error:

Error: Character reference must end with the ';' delimiter.

Yuriy Faktorovich
Sorry it is my typo, I have corrected it, it should be ends with ; in my input. Are they valid XML strings which could be used in XML element values?
George2
The validator said it is invalid, but why? How to filter out such character?
George2
You'd like to remove all such characters from the XML file?
Yuriy Faktorovich
+2  A: 

As others have suggested, there was a semi-colon missing, and use the validator. But also note that not all characters are legal, even if the input format is technically OK.

The following document if failed by the validator:

<?xml version="1.0" encoding="utf-8"?>
<Text>&#x4;</Text>

This one does validate:

<?xml version="1.0" encoding="utf-8"?>
<Text>&#x32;</Text>

For information on characters to use or avoid, this seems interesting.

Fredrik Mörk
Sorry it is my typo, I have corrected it, it should be ends with ; in my input. How to filter out or check whether a XML file is valid or not for characters begin with ?
George2