Help Center

Local Navigation

Object: DOMParser

Availability

BlackBerry® Device Software version 4.7.1 or later

The DOMParser object provides the parseFromString() method, which creates an XML document from a XML string.

The BlackBerry® Browser always parses the current page into a DOM document, but you can also create a DOM from an XML string that you construct, or an XML string that you retrieve from a remote location.

DOMParser methods

Method name

Description

Availability

parseFromString()

Converts a string into an XML document.

4.7.1 or later

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 )
Next topic: Object: Element

Was this information helpful? Send us your comments.