Solved

Error parsing XML in Firefox. No valid Character ""

Posted on 2008-10-07
5
2,540 Views
Last Modified: 2013-12-07
Hello everyone, I have a problem parsing an XML file on Firefox. The XML i generated with a C# code which does not have any problem,  I use JavaScript for parsing other XML documents and there are no problems. But with my application (C#), sometimes an invalid character is set to an attribute of a node when the XML is generated.

Here is a description of my problem.

The information of this node is gotten from a record in a table of an MSI file.

dir: install
file: setup.msi
table: control
record:
    Dialog_                  Control                Type                     Attibutes              Text
    "ThisDialog"          "myControl"         "ScrollBarText"        "7"                 "The text 
 I want to parse it "



I dont have problems parsing 
 but with 

The complete Message I recieve on Firebug is
Error de lectura XML: referencia a un número de carácter no válido Ubicación:"path of XML File"

In english should be something like "XML reading Error: reference to a no valid character number located: "path of XML file""

I'll attach the Java Script code when i create the XMLDOM object.

I've benn thinking about replace that character for 
 or simply remove it from the "Text" Attribute but i dont have problems when i open it with IE.

So Im not sure if there is a way to parse that character. Any solution will be glad.
<dir name="install">
   <file name="setup.msi">
      <table name="Control">
         <record Dialog_="ThisDialog" Control= "myControl" Type="ScrollBarText" Attributes="7" Text="This is my text &#xA; and i want to parse it &#xF;" />
      </table>
   </file>
</dir>
 
 
JavaScript Code
 
 
xmlDoc = document.implementation.createDocument("", "", null);
xmlDoc.async = false;
try {xmlDoc.load(xmlFile);}
catch (oError) {alert(oError.description + oError);return false; }
xmlObj=xmlDoc.documentElement; <-----Here is the error xmlObj gets a <parsererror> node, so, Im not able to process the data on the web page.

Open in new window

0
Comment
Question by:AlexIraMty
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 22667151
what happens if you change it to
&#15;

instead?

It is not a visible char anyway
0
 

Author Comment

by:AlexIraMty
ID: 22669613
I tried changing the char directly on the XML but soes not work. Actually that char does not supose that is set by user or by me, The C# application read a directory a automatically generates the XML tree with the attributes of each file or folder, so, the record inside the table inside msi comes with that char, its imposible change, only detect the node that contaisn in the attribute Text that char. I try to to this with the next Xpaht predicate.


string qDataNode = "//merge/data";
string query = "descendant::record[@Text[contains(.,'&#xF')]]";
XmlNode root = xmlDoc.DocumentElement;
XmlNode temp;
XmlNodeList node;
temp = root.SelectSingleNode(qDataNode);
node = temp.SelectNodes(query);
 
// if I try with the next code it returns a some nodes but im not
//able to find that node with le last predicate
 
string qDataNode = "//merge/data";
string query = "descendant::record[@Control[contains(.,'myControl')]]";
XmlNode root = xmlDoc.DocumentElement;
XmlNode temp;
XmlNodeList node;
temp = root.SelectSingleNode(qDataNode);
node = temp.SelectNodes(query);
 
 
//supose that XML has now the next structure
 
<merge>
   <data>
      <dir name="install">
         <file name="setup.msi">
            <table name="Control">
               <record Dialog_="ThisDialog" Control= "myControl" Type="ScrollBarText" Attributes="7" Text="This is my text &#xA; and i want to parse it &#xF;" />
               <record Dialog_="Newdialog" Control= "BannerLine" Type="Line" Attributes="1" Text="" />
            </table>
            <table name="Other_table">
               <record Dialog_="ReadyToInstall" Control="Branding2" Type="Text" X="3" Y="228"/>
               <record Dialog_="SetupError" Control="I" Type="PushButton" X="192" Y="80" Text = "This is other text with no invalid chars"/>
            </table>
         </file>
         <file name="setup.exe" size="6354" />
         <file name="newfile.dat" size ="1" />
      </dir>
      <dir name="otrodir">
         <dir name="DirInside_otrodir">
            <file name="last_file.ini">
         <dir/>
         <file name="update.exe" size="123">
      </dir>
   </data>
</merge>

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 22669876
Sorry, I have no other ideas
0
 

Accepted Solution

by:
AlexIraMty earned 0 total points
ID: 22715975
Well, I dont know if I have to set more points to my questions in order to get assistance from more people but I finally found a way to solve my own problem. I think I'll start to try to answer questions instead of ask them. Well Here is my solution...
//I decalrated next function
 
static XmlDocument delNoValidChars (XmlDocument xmlDoc)
{    
    StringWriter sw = new StringWriter();
    XmlTextWriter xw = new XmlTextWriter(sw);
    string temp, str;
    xmlDoc.WriteTo(xw);
    //str = xw.ToString();
    str = sw.ToString();
    temp = str;
    if (str.Contains("&#xF;"))
        str = sw.ToString().Replace("&#xF;", "");
    xmlDoc = new XmlDocument();
    xmlDoc.LoadXml(str);
    return xmlDoc;
}
 
//I dont think I have to explain it to much, the code talks by it self
 
//There are 10 kinds of people, those who understand binary and those who do not.

Open in new window

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 22718499
Great.

I fixed your spelling in the joke for you ;)))
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question