XmlReader и двоеточие
От: PowerGUEST  
Дата: 09.11.06 10:41
Оценка:
Привет!

Есть код на C# который парсит XML (пример взят из MSDN)

            // Create a resolver with default credentials.
            XmlUrlResolver resolver = new XmlUrlResolver();
            resolver.Credentials = System.Net.CredentialCache.DefaultCredentials;

            // Set the reader settings object to use the resolver.
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ConformanceLevel = ConformanceLevel.Fragment;
            settings.IgnoreWhitespace = true;
            settings.IgnoreComments = true; 
            settings.XmlResolver = resolver;
            settings.ValidationType = ValidationType.None;

            // Create the XmlReader object.
            XmlReader reader = XmlReader.Create(@"C:\TEMP\rep.xml", settings);

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    if (reader.IsEmptyElement)
                        Console.WriteLine("<{0}/>", reader.Name);
                    else
                    {
                        Console.Write("<{0}> ", reader.Name);
                        reader.Read(); // Read the start tag.
                        if (reader.IsStartElement())  // Handle nested elements.
                            Console.Write("\r\n<{0}>", reader.Name);
                        Console.WriteLine(reader.ReadString());  //Read the text content of the element.
                    }
                }
            }


Есть сам XML


<?xml:stylesheet type="text/xsl" href="http://localhost/stylesheets/style.xsl"?>
<?xml version = "1.0" encoding = "Windows-1251"?>

<root />


В результате получаю исключение... Ругается на двоеточие при определении стиля... Как вылечить?

System.Xml.XmlException was unhandled
  Message="The ':' character, hexadecimal value 0x3A, cannot be included in a name. Line 1, position 6."
  Source="System.Xml"
  LineNumber=1
  LinePosition=6
  SourceUri="file:///C:/TEMP/rep.xml"
  StackTrace:
       at System.Xml.XmlTextReaderImpl.Throw(Exception e)
       at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
       at System.Xml.XmlTextReaderImpl.Throw(Int32 pos, String res, String[] args)
       at System.Xml.XmlTextReaderImpl.ParseQName(Boolean isQName, Int32 startOffset, Int32& colonPos)
       at System.Xml.XmlTextReaderImpl.ParseName()
       at System.Xml.XmlTextReaderImpl.ParsePI(BufferBuilder piInDtdStringBuilder)
       at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
       at System.Xml.XmlTextReaderImpl.Read()
       at ComplexReport.MainForm.buttonOk_Click(Object sender, EventArgs e) in C:\Documents and Settings\Саушкин Андрей\My Documents\Visual Studio 2005\Projects\TELEMAX\ComplexReport\MainForm.cs:line 36
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at ComplexReport.Program.Main() in C:\Documents and Settings\Саушкин Андрей\My Documents\Visual Studio 2005\Projects\TELEMAX\ComplexReport\Program.cs:line 17
       at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()


Спасибо!
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.