Name cannot begin with the ' ' character

后端 未结 9 1245
抹茶落季
抹茶落季 2021-01-01 08:57

I\'m parsing some XML in C#. I\'m getting it from a database, and so converting it to a MemoryStream before reading it with an XmlTextReader. The problem is that I get this

相关标签:
9条回答
  • You also should be carefull and avoid expressions like:

    <e order="0" type="custom" name= "test">
    

    The blank space that follows the name's equal could make your code crash

    0 讨论(0)
  • 2021-01-01 09:19

    If in SSIS, just go to Solution Explorer, select the project then select "Rebuild Solution" from the Build menu option.

    0 讨论(0)
  • 2021-01-01 09:22

    Your error message is quite explicit, you have an error at posn 3 in line 1. Try <?xml -- no space.

    0 讨论(0)
  • 2021-01-01 09:23

    Remove the first space in the document:

    <?xml version="1.0" encoding="utf-8"?>
    
    0 讨论(0)
  • 2021-01-01 09:23

    I was getting the same error reading an XML file.

    It turned out I had an errant < character in my file.

    I was commenting out certain child nodes and when erasing one of the comment tags, I left an extra < in the file. The error message came back "Name cannot begin with the '\r' character" and this question was the top google result for that exact search.

    <node>
        <!-- <child /> --><
        <child />
        <child />
    </node>
    
    0 讨论(0)
  • 2021-01-01 09:23

    I had a lot of errors because of this. Make sure you don't have spaces. There are two places I removed spaces that worked for me.

    Was:

    xmlns: xsi="http://www.w3.org/2001/XMLSchema-instance"
    

    What worked:

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    

    There was a space here too: < abc:def >. Remove all the spaces around the < and the >.

    0 讨论(0)
提交回复
热议问题