Solved

Error parsing XML in Firefox. No valid Character ""

Posted on 2008-10-07
5
2,552 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.
Suggested Courses

615 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