Questions tagged [domparser]

A DOMParser can parse XML or HTML source stored in a string into a DOM Document.

The DOMParser is specifically used in Javascript to parse XML and HTML sources, however other languages may provide DOMParsers as well. In Javascript the DOMParser is specified in DOM Parsing and Serialization.

543 questions
276
votes
8 answers

How to do a wildcard element name match with "querySelector()" or "querySelectorAll()" in JavaScript?

Is there a way to do a wildcard element name match using querySelector or querySelectorAll? The XML document I'm trying to parse is basically a flat list of properties I need to find elements that have certain strings in their names. I see support…
Erik Andersson
  • 2,761
  • 2
  • 14
  • 3
268
votes
7 answers

What is the difference between SAX and DOM?

I read some articles about the XML parsers and came across SAX and DOM. SAX is event-based and DOM is tree model -- I don't understand the differences between these concepts. From what I have understood, event-based means some kind of event happens…
user414967
  • 5,225
  • 10
  • 40
  • 61
123
votes
2 answers

Parse XML using JavaScript

I need to be able to parse XML using JavaScript. The XML will be in a variable. I would prefer not to use jQuery or other frameworks. I have looked at this, XML > jQuery reading.
user2574350
  • 1,383
  • 3
  • 10
  • 7
33
votes
3 answers

JavaScript DOMParser access innerHTML and other properties

I am using the following code to parse a string into DOM: var doc = new DOMParser().parseFromString(string, 'text/xml'); Where string is something like content. typeof doc gives me object. If I…
DADU
  • 6,482
  • 7
  • 42
  • 64
25
votes
5 answers

Preserve Line Breaks - Simple HTML DOM Parser

When using PHP Simple HTML DOM Parser, is it normal that line breaks tags are stripped out?
Tim
  • 251
  • 1
  • 3
  • 3
23
votes
2 answers

What is the point of creating new DOMParser instances?

If you look at the example of DOMParser from MDN: var parser = new DOMParser(); var doc = parser.parseFromString(stringContainingXMLSource, "application/xml"); // returns a Document, but not a SVGDocument nor a HTMLDocument parser = new…
kasbah
  • 903
  • 5
  • 23
20
votes
7 answers

How to strip a tag and all of its inner html using the tag's id?

I have the following html: bla bla bla bla
more text
And even more text
bla bla bla I want to remove everything starting…
rockstardev
  • 13,479
  • 39
  • 164
  • 296
16
votes
6 answers

Adding linebreak in xml file before root node

I am trying to add line break after my comments above the root node in XML document. I need something like this: But What I was able to get…
Murali Krishna
  • 163
  • 1
  • 1
  • 6
16
votes
3 answers

Difference among XML SAX parser, Pull parser & DOM Parser in android

I want to know what's the difference between XML SAX parser, Pull parser & DOM parser in Android. In which condition, which one is better in performance and implementation? Thanx. Khobaib.
Khobaib
  • 1,577
  • 3
  • 21
  • 29
15
votes
1 answer

Parse HTML String to DOM and convert it back to string

I've got an HTML string e.g. '

Hello World!

' I parse this HTML string to DOM using DOMParser().parseFromString(), because I want to change the innerHTML of some specific elements. That's why I parse the HTML string to…
webta.st.ic
  • 4,781
  • 6
  • 48
  • 98
14
votes
5 answers

javascript: read plain html-string and using DOMparser change links path

In my angular app using one of WYSIWYG i can insert links without protocol. And this is bad: i need to parse string and change all link's (if thay didn't have protocol to http://...) and i try to do so: var content =…
brabertaser19
  • 5,678
  • 16
  • 78
  • 184
12
votes
2 answers

Parsing XML in a Web Worker

I have been using a DOMParser object to parse a text string to an XML tree. However it is not available in the context of a Web Worker (and neither is, of course, document.ELEMENT_NODE or the various other constants that would be needed). Is there…
user1127813
  • 299
  • 3
  • 8
11
votes
2 answers

Determining if at leaf node with SAX parser

Using org.xml.sax.helpers.DefaultHandler, can you determine whether you're at a leaf node within endElement(String, String, String)? Or do you need to use a DOM parser to determine this?
Paul Reiners
  • 8,576
  • 33
  • 117
  • 202
9
votes
2 answers

How to parse a XML string in a Firefox addon using Add-on SDK

I am trying to create a FF AddOn that brings some XML data from a website. But I can't find a way to parse my RESPONSE. First I used DOMParser but I get this error: ReferenceError: DOMParser is not defined. Someone suggested to use…
kriztean
  • 229
  • 3
  • 13
9
votes
3 answers

Why is DOMParser not preserving inline styles of parsed DOM?

I am simply trying to parse and append a JavaScript string as a DOM element. I have found two quick ways to do this, one of which is using DOMParser as seen in this popular SO answer. Both methods work, however, the DOMParser approach for some…
scniro
  • 16,844
  • 8
  • 62
  • 106
1
2 3
36 37