views:

42

answers:

2

Hello, help me please i'm having the following issue:

I'm trying to read a XML file that looks like this:

<service  />
<parameters>
  <parametro nombreParametro="payment" valorParametro="&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;" tipoParametro="string" />
</parameters>

The xml file is well formed, but as you can see, i have an &lt; < and &gt; > characters as attribute on some elements and the problem is that when i tried to read the file like this:

xmlDoc.LoadXml(stringWithXmlFileContent);

It gives me the following error:

Additional information: '<', hexadecimal value 0x3C, is not a valid character or attribute. Line XX, position XX.

What should i do to avoid this error, i don't want to make a Replace cause i'm building a generic method.

Thanks in advance.

A: 

Seems your XML file isnt well-formed, as you must have a single root element.

Can you tell us how are your building this file?

Rubens Farias
+1  A: 

I can't reproduce this, assuming that what you posted was only a portion of the XML file. (If it was the whole file, then the problem is it doesn't have a single root element, as Rubens said in his answer). Here's a short but complete program showing the same attribute value not having a problem:

using System;
using System.Xml;

public class Test
{
    public static void Main(String[] args)
    {
        string xml = "<element attr=\"&lt;?xml version=&quot;1.0&quot;"
            + " encoding=&quot;utf-16&quot;?&gt;\" />";

        XmlDocument doc = new XmlDocument();
        doc.LoadXml(xml);
        Console.WriteLine(doc.OuterXml);
    }
}

Can you edit your question to include a similar program which does show the problem?

Jon Skeet