Method: DOMParser.parseFromString()

Availability

BlackBerry Device Software version 4.7.1 or later

The parseFromString() method converts a string into an XML document.

Syntax

DOMParser.parseFromString( string, mimeType )

Parameters

Parameter

Type

Description

string

String

Specifies the string of text.

mimeType

String

Specifies the content type of the resulting XML document. This parameter can have one of the following values:

  • application/xml
  • application/xhtml+xml
  • text/xml

Return values

This method returns an XML document. If the parsing process fails, an error document is returned.

Exceptions

No exceptions are thrown. If the parsing process cannot be succesfully completed, an error document is returned.

Code sample: Converting a string into XML and back to a string again

var xmlString = "<?xml version='1.0' ?>\
<root>\
	<level1>\
		<option>Option1</option>\
		<option>Option2</option>\
		<option>Option3</option>\
	</level1>\
</root>";

var parser = new DOMParser();
var xmlDocument = parser.parseFromString( xmlString, "text/xml" );

var serializer = new XMLSerializer();
var string = serializer.serializeToString( xmlDocument ); 
alert( string )

Was this information helpful? Send us your comments.