domparser

Android XML DOM Parsing when you have namespaces?

[亡魂溺海] 提交于 2019-12-06 14:36:24
问题 When you have xml nodes with namespaces like: <ns:abc> then getElementsByTagName("abc"); fails, but getElementsByTagName("ns:abc"); works. But the issue is I don't know what is the namespace prefix chosen. Also for me, getElementsByTagNameNS("*", "abc"); and getElementsByTagNameNS("http://abcnamespace.com", "abc"); both return null. If device is of interest, I am using CM7 on Nook. I don't want to use SAX, any other clean way to read the node lists. 回答1: DocumentBuilderFactory

Retrieve values from Json and update the XML

こ雲淡風輕ζ 提交于 2019-12-06 13:35:34
问题 I am trying to combine multiple xmls into one xml using DOM parser. I am fairly new to this process. I am having issue while updating the values and the order of the xml which I will be getting from JSON. Here, # of xmls to combine is equal to the # json. Document outputDoc = db.parse(baseXml); Node outputNode = outputDoc.getElementsByTagName("Entry").item(0); for (String inputXml : inputXmls) { Document inputDoc = db.parse(inputXml); inputDoc.normalize(); NodeList nodeList = inputDoc

ParseFromString throws error in IE, but not in Chrome

半城伤御伤魂 提交于 2019-12-05 17:19:15
I'm using a KML plugin for leaflet that works great in Google Chrome. In IE, however, It throws an error at the following code. parser=new DOMParser(); console.log(url) // outputs: "path/to/kmlfile.kml" in Chrome debugger url=parser.parseFromString(url,"text/xml"); //This line throws a parser error in IE 11, but is fine in Chrome It seems to me that there is a mistake in this code - the author should pass an actual XML string, not just a url to an XML document to the parser.parseFromString() function. It makes sense that the parser would have an error, as a path to a file is not a valid XML

Node + xmldom: How do I change the value of a single XML field in javascript?

纵然是瞬间 提交于 2019-12-05 10:49:19
Using node v.0.10.29, Express v4.12.0, and xmldom v0.1.19, I'm trying to do the following: Steps Read an XML file into a string Convert the string into an XML object using xmldom Set the <name>default</name> field to <name>test</name> Convert the XML object back into a string Problem The problem is that after I set the <name> field, it sets correctly in the object, but when I convert it to a string, the <name> field is back to being the old value (wrong). Code Here's what the code looks like for this: var fs = require('fs'); var DOMParser = require('xmldom').DOMParser; var XMLSerializer =

XML parsing : encoding utf-8 & UTF-8

亡梦爱人 提交于 2019-12-05 06:04:45
问题 I am trying to parse the values from this LINK, whose xml encoding is like this <?xml version="1.0" encoding="utf-8"?> when I tried to get response throws message in logcat as shown 11-19 17:25:13.350: W/System.err(3360): This is not valid URL 11-19 17:25:13.350: W/System.err(3360): java.lang.NullPointerException When I tried with some other LINK ,whose encoding is like this <?xml version="1.0" encoding="UTF-8"?> It works fine, I can parse the values. is xml parsing failing due encoding not

Difference in doing Android XML Parsing using DOM Parser and SAX Parser

廉价感情. 提交于 2019-12-05 04:35:53
问题 I would like to know what exact advantage is gained in doing Android XML Parsing using DOM Parser and SAX Parser? Is it like DOm parser is advantageous than SAX Parser or vice-versa? Please clarify. Thanks, Sen 回答1: Hi SAX Parsing is the Best one to implement than DOM, see the difference between these two in the following: DOM The Nodes are in the form of Tree Structure Memory: It Occupies more memory, DOM is only preffered in the case of small XML documents Slower at runtime Stored as an

Parse anchor tags which have img tag as child element

末鹿安然 提交于 2019-12-05 02:56:34
问题 I need to find all anchor tags, which have an img tag as child element. Consider the following cases, <a href="test1.php"> <img src="test1.jpg" alt="Test 1" /> </a> <a href="test2.php"> <span> <img src="test2.jpg" alt="Test 2" /> </span> </a> My requirement is to generate a list of href attributes along with src and alt ie, $output = array( array( 'href' => 'test1.php', 'src' => 'test1.jpg', 'alt' => 'Test 1' ), array( 'href' => 'test2.php', 'src' => 'test2.jpg', 'alt' => 'Test 2' ) ); How

Parsing XMLHttpRequest() result (using XPath)

白昼怎懂夜的黑 提交于 2019-12-04 20:03:08
I need in JavaScript to load in variable contents of another page from the same site and then get data from that contents (parse XML). I have gotten in text string variable the page's HTML using XMLHttpRequest() and responseText property. After that I converted text string into xml object (DOMParser) and tried to use XPath. In FireFox's console I saw error: Node cannot be used in a document other than the one in which it was created How can I convert XMLHttpRequest() result into document object to process it using XPath? How I should use document.evaluate with this object? Is there the easier

Android XML DOM Parsing when you have namespaces?

…衆ロ難τιáo~ 提交于 2019-12-04 19:18:13
When you have xml nodes with namespaces like: <ns:abc> then getElementsByTagName("abc"); fails, but getElementsByTagName("ns:abc"); works. But the issue is I don't know what is the namespace prefix chosen. Also for me, getElementsByTagNameNS("*", "abc"); and getElementsByTagNameNS("http://abcnamespace.com", "abc"); both return null. If device is of interest, I am using CM7 on Nook. I don't want to use SAX, any other clean way to read the node lists. Evgeny Zhuravlev DocumentBuilderFactory.setNamespaceAware(true) should fix your problem. 来源: https://stackoverflow.com/questions/7076149/android

Javascript xml parser: how to get nodes that have “:” in the name

浪子不回头ぞ 提交于 2019-12-04 15:38:59
I have the following code where i'm trying to get the c:CreationDate nodes: value = '<?xml version="1.0" encoding="UTF-8"?><content><c:CreationDate>2010-09-04T05:04:53Z</c:CreationDate></content>'; xml = (new DOMParser()).parseFromString(value, 'text/xml'); console.log(xml.getElementsByTagName('c:CreationDate')); Unfortunately it's returning an empty array, instead of an array with the node that is in the xml. I think that this is caused because of the ":" symbol. Is there a way to escape it? Note: Please, do not suggest usage on childNodes or things like this. This will not work for me since