Solved

Error parsing XML in Firefox. No valid Character ""

Posted on 2008-10-07
5
2,515 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
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)
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now