public void XmlParsingShouldThrow() { var parser = new DOMParser(); if (!BrowserHelper.IsPhantomJs()) { Assert.Throws(() => { parser.ParseFromString("<root></root>", "xml"); }); } else { var d = parser.ParseFromString("<root></root>", "xml"); Assert.Null(d); } }
public static XamlElement Parse(string content) { DOMParser domParser = new DOMParser(); XmlElement xmlElement = domParser.ParseFromString(content, DOMParserSupportedType.ApplicationXml).DocumentElement; if (xmlElement.NodeName == "parsererror" || xmlElement.FirstChild != null && xmlElement.FirstChild.NodeName == "parsererror") { throw new Granular.Exception(GetParserErrorMessage(xmlElement.TextContent)); } return(Parse(xmlElement)); }
/// <summary> /// Converts plain text into a DOM structure. /// Throws an error if XML doesn't parse. /// </summary> /// <param name="text">Text representation.</param> /// <returns>A tree of XML elements.</returns> public static Element textToDom(string text) { var oParser = new DOMParser(); var dom = oParser.ParseFromString(text, "text/xml"); // The DOM should have one and only one top-level node, an XML tag. if (dom == null || dom.FirstChild == null || dom.FirstChild.NodeName.ToLowerCase() != "xml" || dom.FirstChild != dom.LastChild) { // Whatever we got back from the parser is not XML. goog.asserts.fail("Xml.textToDom did not obtain a valid XML tree."); } return((Element)dom.FirstChild); }
public void XmlParsingWorks() { var parser = new DOMParser(); var d = parser.ParseFromString("<root><customer name=\"John\" address=\"Chicago\"></customer></root>", DOMParser.SupportedType.TextXml); Assert.NotNull(d); Assert.AreEqual(1, d.ChildNodes.Length); Assert.NotNull(d.FirstChild); Assert.AreEqual("root", d.FirstChild.NodeName); Assert.AreEqual(1, d.FirstChild.ChildNodes.Length); var c = d.FirstChild.FirstChild; Assert.NotNull(c); Assert.AreEqual("customer", c.NodeName); }
public static void DataLoaded(JsString strRequestResponse) { var parser = new DOMParser(); Document xmlData = parser.ParseFromString(strRequestResponse, "text/xml"); JsCode("xmlData.alltext = strRequestResponse"); if (xmlData != null) { previousXMLData = xmlData; } else { xmlData = previousXMLData; } if (xmlData != null) { JsString outHTML = ""; HtmlElement.GetById("podcastTitle").innerHTML = xmlData.GetElementsByTagName("title")[0].childNodes[0].nodeValue; outHTML += "<table class=\"episodes\">"; NodeList nodeList; nodeList = xmlData.GetElementsByTagName("channel"); if (nodeList.length > 0) { for (int i = 0; i < nodeList.length; i++) { if ((nodeList[i] as Element).GetElementsByTagName("item").length >= 1) { for (int ii = 0; ii < (nodeList[i] as Element).GetElementsByTagName("item").length; ii++) { Node selNode = ((nodeList[i] as Element).GetElementsByTagName("item"))[ii]; JsString strTitle = ""; JsString strPodcastLink = ""; JsString strPodcastMP3 = ""; //JsString strNodeIcon = ""; for (int x = 0; x < selNode.childNodes.length; x++) { if (selNode.childNodes[x].nodeName == "title") { strTitle = selNode.childNodes[x].childNodes[0].nodeValue; } if (selNode.childNodes[x].nodeName == "enclosure") { strPodcastMP3 = (selNode.childNodes[x] as Element).GetAttribute("url"); } if (selNode.childNodes[x].nodeName == "link") { strPodcastLink = selNode.childNodes[x].childNodes[0].nodeValue; } } outHTML += "<table width=\"100%\" onclick=\"playPodcast('" + strPodcastMP3 + "');\">"; outHTML += "<tr>"; outHTML += "<td class=\"ListItem\" align=\"left\" valign=\"middle\">"; outHTML += strTitle; outHTML += "</td>"; outHTML += "</tr></table>"; } } } outHTML += "</table>"; HtmlElement.GetById("podcastEpisodes").innerHTML = outHTML; } } }