473,395 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

convert javascript string to xml string

how can i convert a javascript string to xml string?
Feb 29 '08 #1
7 4202
acoder
16,027 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. var XMLobj = (new DOMParser()).parseFromString(theString, "text/xml")
Feb 29 '08 #2
Expand|Select|Wrap|Line Numbers
  1. var XMLobj = (new DOMParser()).parseFromString(theString, "text/xml")
the problem that i am facing is the string that is to be passed to the parseFromString method is a xmlstring. i have an xml file stored in my local file system. but,when i read the file using javascript it is assigned to a javascript string n i m getting a parseerror when i try parse it using parseFromString method.
Feb 29 '08 #3
acoder
16,027 Expert Mod 8TB
Have you checked that the XML file is valid?
Feb 29 '08 #4
i am storing a string obtained by converting a document fragment using the method serializeToString in the xml file. The problem that i could figure out was the root element of the document fragment is not converted (only the child nodes are converted to string).So the resulting xml doc is not having a root element. How can i fix this??
Mar 3 '08 #5
acoder
16,027 Expert Mod 8TB
Can you post the code that you've tried.
Mar 3 '08 #6
Expand|Select|Wrap|Line Numbers
  1. var serializer =Components.classes["@mozilla.org/xmlextras/xmlserializer;1"].createInstance(Components.interfaces.nsIDOMSerializer);
  2. var string = serializer.serializeToString(this.rootnode);
  3.  
  4. var out = Components.classes["@mozilla.org/network/file-output-stream;1"].createInstance(Components.interfaces.nsIFileOutputStream);
  5. out.init(this.file, 0x20 | 0x02, 0666, null);
  6. out.write(string,string.length);
  7. out.flush();
  8. out.close();
Mar 3 '08 #7
acoder
16,027 Expert Mod 8TB
See parsing and serializing XML.
Mar 3 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Andrew V. Romero | last post by:
At work we have an excel file that contains the list of medications and their corresponding strengths. I would like to save the excel file as a text list and paste this list into a javascript...
4
by: CSharpener | last post by:
This should be *so* easy! How do I convert a Byte or int to a binary string representation in C# In JavaScript, it goes like this for an int: javascript:(123).toString(2 or...
52
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
1
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number?...
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number?...
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number?...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.