public static void init() { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.IgnoringElementContentWhitespace = true; documentBuilderFactory.IgnoringComments = true; documentBuilderFactory.Coalescing = true; try { DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document document = documentBuilder.parse(typeof(PreDecrypt).getResourceAsStream("PreDecrypt.xml")); Element configuration = document.DocumentElement; load(configuration); } catch (ParserConfigurationException e) { Console.WriteLine(e); } catch (SAXException e) { Console.WriteLine(e); } catch (IOException e) { Console.WriteLine(e); } }
public virtual void TestTaskAttemptIdXMLCounters() { WebResource r = Resource(); IDictionary <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> jobsMap = appContext .GetAllJobs(); foreach (JobId id in jobsMap.Keys) { string jobId = MRApps.ToString(id); foreach (Task task in jobsMap[id].GetTasks().Values) { string tid = MRApps.ToString(task.GetID()); foreach (TaskAttempt att in task.GetAttempts().Values) { TaskAttemptId attemptid = att.GetID(); string attid = MRApps.ToString(attemptid); ClientResponse response = r.Path("ws").Path("v1").Path("history").Path("mapreduce" ).Path("jobs").Path(jobId).Path("tasks").Path(tid).Path("attempts").Path(attid). Path("counters").Accept(MediaType.ApplicationXml).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationXmlType, response.GetType()); string xml = response.GetEntity <string>(); DocumentBuilderFactory dbf = DocumentBuilderFactory.NewInstance(); DocumentBuilder db = dbf.NewDocumentBuilder(); InputSource @is = new InputSource(); @is.SetCharacterStream(new StringReader(xml)); Document dom = db.Parse(@is); NodeList nodes = dom.GetElementsByTagName("jobTaskAttemptCounters"); VerifyHsTaskCountersXML(nodes, att); } } } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void load(java.net.URL url, PropagationSpecs propagationSpecs) throws org.maltparser.core.exception.MaltChainedException public virtual void load(URL url, PropagationSpecs propagationSpecs) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Element root = null; root = db.parse(url.openStream()).DocumentElement; if (root == null) { throw new PropagationException("The propagation specification file '" + url.File + "' cannot be found. "); } readPropagationSpecs(root, propagationSpecs); } catch (IOException e) { throw new PropagationException("The propagation specification file '" + url.File + "' cannot be found. ", e); } catch (ParserConfigurationException e) { throw new PropagationException("Problem parsing the file " + url.File + ". ", e); } catch (SAXException e) { throw new PropagationException("Problem parsing the file " + url.File + ". ", e); } }
public virtual void discover(string descriptionUrl) { DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.IgnoringElementContentWhitespace = true; documentBuilderFactory.IgnoringComments = true; documentBuilderFactory.Coalescing = true; try { URL url = new URL(descriptionUrl); DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder(); Document description = documentBuilder.parse(url.openStream()); parseIGDdata(description); this.descriptionUrl = descriptionUrl; } catch (ParserConfigurationException e) { Console.WriteLine("Discovery", e); } catch (SAXException e) { Console.WriteLine("Discovery", e); } catch (MalformedURLException e) { Console.WriteLine("Discovery", e); } catch (IOException e) { Console.WriteLine("Discovery", e); } }
/// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/> /// <exception cref="System.Exception"/> public virtual void VerifySchedulerFifoXML(string xml) { DocumentBuilderFactory dbf = DocumentBuilderFactory.NewInstance(); DocumentBuilder db = dbf.NewDocumentBuilder(); InputSource @is = new InputSource(); @is.SetCharacterStream(new StringReader(xml)); Document dom = db.Parse(@is); NodeList nodesSched = dom.GetElementsByTagName("scheduler"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, nodesSched.GetLength ()); NodeList nodes = dom.GetElementsByTagName("schedulerInfo"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, nodes.GetLength ()); for (int i = 0; i < nodes.GetLength(); i++) { Element element = (Element)nodes.Item(i); VerifyClusterSchedulerFifoGeneric(WebServicesTestUtils.GetXmlAttrString(element, "xsi:type"), WebServicesTestUtils.GetXmlString(element, "qstate"), WebServicesTestUtils .GetXmlFloat(element, "capacity"), WebServicesTestUtils.GetXmlFloat(element, "usedCapacity" ), WebServicesTestUtils.GetXmlInt(element, "minQueueMemoryCapacity"), WebServicesTestUtils .GetXmlInt(element, "maxQueueMemoryCapacity"), WebServicesTestUtils.GetXmlInt(element , "numNodes"), WebServicesTestUtils.GetXmlInt(element, "usedNodeCapacity"), WebServicesTestUtils .GetXmlInt(element, "availNodeCapacity"), WebServicesTestUtils.GetXmlInt(element , "totalNodeCapacity"), WebServicesTestUtils.GetXmlInt(element, "numContainers") ); } }
/// <summary> /// Loads The XML document. /// </summary> /// <param name="in"> /// is the input stream. </param> /// <exception cref="DOMLoaderException"> /// DOM loader exception. </exception> /// <returns> The loaded document. </returns> // XXX: fix error reporting public virtual Document load(System.IO.Stream @in) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.NamespaceAware = true; factory.Validating = _validating; try { DocumentBuilder builder = factory.newDocumentBuilder(); // if(_validating) { builder.ErrorHandler = new ErrorHandlerAnonymousInnerClass(this); // } return(builder.parse(@in)); } catch (SAXException e) { throw new DOMLoaderException("SAX exception: " + e.Message); } catch (ParserConfigurationException e) { throw new DOMLoaderException("Parser configuration exception: " + e.Message); } catch (IOException e) { throw new DOMLoaderException("IO exception: " + e.Message); } }
/// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/> /// <exception cref="System.Exception"/> public virtual void VerifyClusterMetricsXML(string xml) { DocumentBuilderFactory dbf = DocumentBuilderFactory.NewInstance(); DocumentBuilder db = dbf.NewDocumentBuilder(); InputSource @is = new InputSource(); @is.SetCharacterStream(new StringReader(xml)); Document dom = db.Parse(@is); NodeList nodes = dom.GetElementsByTagName("clusterMetrics"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, nodes.GetLength ()); for (int i = 0; i < nodes.GetLength(); i++) { Element element = (Element)nodes.Item(i); VerifyClusterMetrics(WebServicesTestUtils.GetXmlInt(element, "appsSubmitted"), WebServicesTestUtils .GetXmlInt(element, "appsCompleted"), WebServicesTestUtils.GetXmlInt(element, "reservedMB" ), WebServicesTestUtils.GetXmlInt(element, "availableMB"), WebServicesTestUtils. GetXmlInt(element, "allocatedMB"), WebServicesTestUtils.GetXmlInt(element, "reservedVirtualCores" ), WebServicesTestUtils.GetXmlInt(element, "availableVirtualCores"), WebServicesTestUtils .GetXmlInt(element, "allocatedVirtualCores"), WebServicesTestUtils.GetXmlInt(element , "totalVirtualCores"), WebServicesTestUtils.GetXmlInt(element, "containersAllocated" ), WebServicesTestUtils.GetXmlInt(element, "totalMB"), WebServicesTestUtils.GetXmlInt (element, "totalNodes"), WebServicesTestUtils.GetXmlInt(element, "lostNodes"), WebServicesTestUtils .GetXmlInt(element, "unhealthyNodes"), WebServicesTestUtils.GetXmlInt(element, "decommissionedNodes" ), WebServicesTestUtils.GetXmlInt(element, "rebootedNodes"), WebServicesTestUtils .GetXmlInt(element, "activeNodes")); } }
/// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/> /// <exception cref="System.Exception"/> public virtual void VerifyClusterInfoXML(string xml) { DocumentBuilderFactory dbf = DocumentBuilderFactory.NewInstance(); DocumentBuilder db = dbf.NewDocumentBuilder(); InputSource @is = new InputSource(); @is.SetCharacterStream(new StringReader(xml)); Document dom = db.Parse(@is); NodeList nodes = dom.GetElementsByTagName("clusterInfo"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, nodes.GetLength ()); for (int i = 0; i < nodes.GetLength(); i++) { Element element = (Element)nodes.Item(i); VerifyClusterGeneric(WebServicesTestUtils.GetXmlLong(element, "id"), WebServicesTestUtils .GetXmlLong(element, "startedOn"), WebServicesTestUtils.GetXmlString(element, "state" ), WebServicesTestUtils.GetXmlString(element, "haState"), WebServicesTestUtils.GetXmlString (element, "haZooKeeperConnectionState"), WebServicesTestUtils.GetXmlString(element , "hadoopVersionBuiltOn"), WebServicesTestUtils.GetXmlString(element, "hadoopBuildVersion" ), WebServicesTestUtils.GetXmlString(element, "hadoopVersion"), WebServicesTestUtils .GetXmlString(element, "resourceManagerVersionBuiltOn"), WebServicesTestUtils.GetXmlString (element, "resourceManagerBuildVersion"), WebServicesTestUtils.GetXmlString(element , "resourceManagerVersion")); } }
public virtual void TestTaskIdXML() { WebResource r = Resource(); IDictionary <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> jobsMap = appContext .GetAllJobs(); foreach (JobId id in jobsMap.Keys) { string jobId = MRApps.ToString(id); foreach (Task task in jobsMap[id].GetTasks().Values) { string tid = MRApps.ToString(task.GetID()); ClientResponse response = r.Path("ws").Path("v1").Path("mapreduce").Path("jobs"). Path(jobId).Path("tasks").Path(tid).Accept(MediaType.ApplicationXml).Get <ClientResponse >(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationXmlType, response.GetType()); string xml = response.GetEntity <string>(); DocumentBuilderFactory dbf = DocumentBuilderFactory.NewInstance(); DocumentBuilder db = dbf.NewDocumentBuilder(); InputSource @is = new InputSource(); @is.SetCharacterStream(new StringReader(xml)); Document dom = db.Parse(@is); NodeList nodes = dom.GetElementsByTagName("task"); for (int i = 0; i < nodes.GetLength(); i++) { Element element = (Element)nodes.Item(i); VerifyAMSingleTaskXML(element, task); } } } }
public static Document LoadXML(string path) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); return(dbf.newDocumentBuilder().parse(new BufferedInputStream(new FileInputStream(path)))); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void load(java.net.URL specModelURL) throws org.maltparser.core.exception.MaltChainedException public virtual void load(URL specModelURL) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Element root = null; root = db.parse(specModelURL.openStream()).DocumentElement; if (root == null) { throw new FlowException("The flow chart system file '" + specModelURL.File + "' cannot be found. "); } readChartElements(root); } catch (IOException e) { throw new FlowException("The flow chart system file '" + specModelURL.File + "' cannot be found. ", e); } catch (ParserConfigurationException e) { throw new FlowException("Problem parsing the file " + specModelURL.File + ". ", e); } catch (SAXException e) { throw new FlowException("Problem parsing the file " + specModelURL.File + ". ", e); } }
/// <summary> /// Configures the DocumentBuilderFactory in a way, that it is protected against XML External Entity Attacks. /// If the implementing parser does not support one or multiple features, the failed feature is ignored. /// The parser might not protected, if the feature assignment fails. /// </summary> /// <seealso cref= <a href="https://www.owasp.org/index.php/XML_External_Entity_(XXE)_Prevention_Cheat_Sheet">OWASP Information of XXE attacks</a> /// </seealso> /// <param name="dbf"> The factory to configure. </param> //JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET: //ORIGINAL LINE: private void protectAgainstXxeAttacks(final javax.xml.parsers.DocumentBuilderFactory dbf) private void protectAgainstXxeAttacks(DocumentBuilderFactory dbf) { try { dbf.setFeature("http://xml.org/sax/features/external-general-entities", false); } catch (ParserConfigurationException) { } try { dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); } catch (ParserConfigurationException) { } try { dbf.setFeature("http://xml.org/sax/features/external-parameter-entities", false); } catch (ParserConfigurationException) { } dbf.XIncludeAware = false; dbf.ExpandEntityReferences = false; }
public virtual void TestNodes2XML() { rm.Start(); WebResource r = Resource(); rm.RegisterNode("h1:1234", 5120); rm.RegisterNode("h2:1235", 5121); ClientResponse response = r.Path("ws").Path("v1").Path("cluster").Path("nodes").Accept (MediaType.ApplicationXml).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationXmlType, response.GetType()); string xml = response.GetEntity <string>(); DocumentBuilderFactory dbf = DocumentBuilderFactory.NewInstance(); DocumentBuilder db = dbf.NewDocumentBuilder(); InputSource @is = new InputSource(); @is.SetCharacterStream(new StringReader(xml)); Document dom = db.Parse(@is); NodeList nodesApps = dom.GetElementsByTagName("nodes"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, nodesApps.GetLength ()); NodeList nodes = dom.GetElementsByTagName("node"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 2, nodes.GetLength ()); rm.Stop(); }
public virtual void TestWriteXml() { StringWriter sw = new StringWriter(); ConfServlet.WriteResponse(GetTestConf(), sw, "xml"); string xml = sw.ToString(); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.NewInstance(); DocumentBuilder builder = docBuilderFactory.NewDocumentBuilder(); Document doc = builder.Parse(new InputSource(new StringReader(xml))); NodeList nameNodes = doc.GetElementsByTagName("name"); bool foundSetting = false; for (int i = 0; i < nameNodes.GetLength(); i++) { Node nameNode = nameNodes.Item(i); string key = nameNode.GetTextContent(); System.Console.Error.WriteLine("xml key: " + key); if (TestKey.Equals(key)) { foundSetting = true; Element propertyElem = (Element)nameNode.GetParentNode(); string val = propertyElem.GetElementsByTagName("value").Item(0).GetTextContent(); Assert.Equal(TestVal, val); } } Assert.True(foundSetting); }
public virtual void TestNodeContainerXML() { WebResource r = Resource(); Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application app = new MockApp(1); nmContext.GetApplications()[app.GetAppId()] = app; AddAppContainers(app); Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application app2 = new MockApp(2); nmContext.GetApplications()[app2.GetAppId()] = app2; AddAppContainers(app2); ClientResponse response = r.Path("ws").Path("v1").Path("node").Path("containers") .Accept(MediaType.ApplicationXml).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationXmlType, response.GetType()); string xml = response.GetEntity <string>(); DocumentBuilderFactory dbf = DocumentBuilderFactory.NewInstance(); DocumentBuilder db = dbf.NewDocumentBuilder(); InputSource @is = new InputSource(); @is.SetCharacterStream(new StringReader(xml)); Document dom = db.Parse(@is); NodeList nodes = dom.GetElementsByTagName("container"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 4, nodes.GetLength ()); }
public virtual void TestTasksXML() { WebResource r = Resource(); IDictionary <JobId, Org.Apache.Hadoop.Mapreduce.V2.App.Job.Job> jobsMap = appContext .GetAllJobs(); foreach (JobId id in jobsMap.Keys) { string jobId = MRApps.ToString(id); ClientResponse response = r.Path("ws").Path("v1").Path("mapreduce").Path("jobs"). Path(jobId).Path("tasks").Accept(MediaType.ApplicationXml).Get <ClientResponse>(); NUnit.Framework.Assert.AreEqual(MediaType.ApplicationXmlType, response.GetType()); string xml = response.GetEntity <string>(); DocumentBuilderFactory dbf = DocumentBuilderFactory.NewInstance(); DocumentBuilder db = dbf.NewDocumentBuilder(); InputSource @is = new InputSource(); @is.SetCharacterStream(new StringReader(xml)); Document dom = db.Parse(@is); NodeList tasks = dom.GetElementsByTagName("tasks"); NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, tasks.GetLength ()); NodeList task = dom.GetElementsByTagName("task"); VerifyAMTaskXML(task, jobsMap[id]); } }
/// <summary> /// Parses the option file for option values. /// </summary> /// <param name="fileName"> The option file name (must be a xml file). </param> /// <exception cref="OptionException"> </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void parseOptionInstanceXMLfile(String fileName) throws org.maltparser.core.exception.MaltChainedException public virtual void parseOptionInstanceXMLfile(string fileName) { File file = new File(fileName); try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Element root = db.parse(file).DocumentElement; NodeList containers = root.getElementsByTagName("optioncontainer"); Element container; for (int i = 0; i < containers.Length; i++) { container = (Element)containers.item(i); parseOptionValues(container, i); } } catch (IOException e) { throw new OptionException("Can't find the file " + fileName + ". ", e); } catch (OptionException e) { throw new OptionException("Problem parsing the file " + fileName + ". ", e); } catch (ParserConfigurationException e) { throw new OptionException("Problem parsing the file " + fileName + ". ", e); } catch (SAXException e) { throw new OptionException("Problem parsing the file " + fileName + ". ", e); } }
public static Node Parse(InputStream input) { DocumentBuilderFactory dbFactory = DocumentBuilderFactory.NewInstance(); dbFactory.IgnoringComments = true; dbFactory.IgnoringElementContentWhitespace = true; dbFactory.NamespaceAware = true; dbFactory.Validating = false; try { DocumentBuilder dber = dbFactory.NewDocumentBuilder(); Document doc = dber.parse(input); string tagname = doc.ChildNodes.Item(0).NodeName; NodeList nodes = doc.getElementsByTagName(tagname); return(nodes.Item(0)); } catch (SAXException) { throw new Indeterminate(Indeterminate.IndeterminateProcessingError); } catch (IOException) { throw new Indeterminate(Indeterminate.IndeterminateProcessingError); } catch (ParserConfigurationException) { throw new Indeterminate(Indeterminate.IndeterminateProcessingError); } }
private Document LoadXML(string path) { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); return(factory.newDocumentBuilder().parse(new BufferedInputStream(new FileInputStream(path)))); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public void load(java.net.URL specModelURL, org.maltparser.core.feature.spec.SpecificationModels featureSpecModels) throws org.maltparser.core.exception.MaltChainedException public virtual void load(URL specModelURL, SpecificationModels featureSpecModels) { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Element root = null; root = db.parse(specModelURL.openStream()).DocumentElement; if (root == null) { throw new FeatureException("The feature specification file '" + specModelURL.File + "' cannot be found. "); } readFeatureModels(root, featureSpecModels); } catch (IOException e) { throw new FeatureException("The feature specification file '" + specModelURL.File + "' cannot be found. ", e); } catch (SAXParseException e) { throw new FeatureException("Problem parsing the feature specification XML-file " + specModelURL.File + ". ", e); } catch (ParserConfigurationException e) { throw new FeatureException("Problem parsing the feature specification XML-file " + specModelURL.File + ". ", e); } catch (SAXException e) { throw new FeatureException("Problem parsing the feature specification XML-file " + specModelURL.File + ". ", e); } }
/// <summary>test xml generation</summary> /// <exception cref="Javax.Xml.Parsers.ParserConfigurationException"/> /// <exception cref="System.Exception"></exception> public virtual void TestQueueConfigurationParser() { JobQueueInfo info = new JobQueueInfo("root", "rootInfo"); JobQueueInfo infoChild1 = new JobQueueInfo("child1", "child1Info"); JobQueueInfo infoChild2 = new JobQueueInfo("child2", "child1Info"); info.AddChild(infoChild1); info.AddChild(infoChild2); DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.NewInstance(); DocumentBuilder builder = docBuilderFactory.NewDocumentBuilder(); Document document = builder.NewDocument(); // test QueueConfigurationParser.getQueueElement Element e = QueueConfigurationParser.GetQueueElement(document, info); // transform result to string for check DOMSource domSource = new DOMSource(e); StringWriter writer = new StringWriter(); StreamResult result = new StreamResult(writer); TransformerFactory tf = TransformerFactory.NewInstance(); Transformer transformer = tf.NewTransformer(); transformer.Transform(domSource, result); string str = writer.ToString(); NUnit.Framework.Assert.IsTrue(str.EndsWith("<queue><name>root</name><properties/><state>running</state><queue><name>child1</name><properties/><state>running</state></queue><queue><name>child2</name><properties/><state>running</state></queue></queue>" )); }
protected internal AbstractModelParser() { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); configureFactory(dbf); this.documentBuilderFactory = dbf; }
/// <summary> /// Given a path to a file containing a list of SsurgeonPatterns, returns /// TODO: deal with resources /// </summary> /// <exception cref="System.Exception"/> public virtual IList <SsurgeonPattern> ReadFromFile(File file) { IList <SsurgeonPattern> retList = new List <SsurgeonPattern>(); IDocument doc = DocumentBuilderFactory.NewInstance().NewDocumentBuilder().Parse(file); INodeList patternNodes = doc.GetElementsByTagName(SsurgeonPattern.SsurgeonElemTag); for (int i = 0; i < patternNodes.GetLength(); i++) { INode node = patternNodes.Item(i); if (node.GetNodeType() == NodeConstants.ElementNode) { IElement elt = (IElement)node; SsurgeonPattern pattern = SsurgeonPatternFromXML(elt); retList.Add(pattern); } } INodeList resourceNodes = doc.GetElementsByTagName(SsurgeonPattern.ResourceTag); for (int i_1 = 0; i_1 < resourceNodes.GetLength(); i_1++) { INode node = patternNodes.Item(i_1); if (node.GetNodeType() == NodeConstants.ElementNode) { IElement resourceElt = (IElement)node; SsurgeonWordlist wlRsrc = new SsurgeonWordlist(resourceElt); AddResource(wlRsrc); } } return(retList); }
private static DocumentBuilder newDocumentBuilder() { var factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); return(factory.newDocumentBuilder()); }
/// <summary>Method to load the resource file.</summary> /// <remarks> /// Method to load the resource file. /// generates the root. /// </remarks> /// <param name="resourceInput">InputStream that provides the XML to parse</param> /// <returns/> /// <exception cref="Javax.Xml.Parsers.ParserConfigurationException"/> /// <exception cref="Org.Xml.Sax.SAXException"/> /// <exception cref="System.IO.IOException"/> protected internal virtual Queue LoadResource(InputStream resourceInput) { DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.NewInstance(); //ignore all comments inside the xml file docBuilderFactory.SetIgnoringComments(true); //allow includes in the xml file docBuilderFactory.SetNamespaceAware(true); try { docBuilderFactory.SetXIncludeAware(true); } catch (NotSupportedException e) { Log.Info("Failed to set setXIncludeAware(true) for parser " + docBuilderFactory + NameSeparator + e); } DocumentBuilder builder = docBuilderFactory.NewDocumentBuilder(); Document doc = null; Element queuesNode = null; doc = builder.Parse(resourceInput); queuesNode = doc.GetDocumentElement(); return(this.ParseResource(queuesNode)); }
public void Sign(string unsignedXmlPath, string signedXmlPath, string pfxPath, string pfxPassword) { PrivateKey privateKey; Provider provider; X509Certificate certificate = _LoadCertificate(pfxPath, pfxPassword, out privateKey, out provider); if (certificate != null) { TrustFactory.instance = es.mityc.javasign.trust.TrustExtendFactory.newInstance(); TrustFactory.truster = es.mityc.javasign.trust.MyPropsTruster.getInstance(); PoliciesManager.POLICY_SIGN = new es.mityc.javasign.xml.xades.policy.facturae.Facturae31Manager(); PoliciesManager.POLICY_VALIDATION = new es.mityc.javasign.xml.xades.policy.facturae.Facturae31Manager(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); Document unsignedDocument = dbf.newDocumentBuilder().parse(new BufferedInputStream(new FileInputStream(unsignedXmlPath))); DataToSign dataToSign = new DataToSign(); dataToSign.setXadesFormat(EnumFormatoFirma.XAdES_BES); dataToSign.setEsquema(XAdESSchemas.XAdES_132); dataToSign.setPolicyKey("facturae31"); dataToSign.setAddPolicy(true); dataToSign.setXMLEncoding("UTF-8"); dataToSign.setEnveloped(true); dataToSign.addObject(new ObjectToSign(new AllXMLToSign(), "Description", null, "text/xml", null)); dataToSign.setDocument(unsignedDocument); Object[] res = new FirmaXML().signFile(certificate, dataToSign, privateKey, provider); UtilidadTratarNodo.saveDocumentToOutputStream((Document)res[0], new FileOutputStream(signedXmlPath), true); } }
/// <summary> /// allows subclasses to configure the <seealso cref="DocumentBuilderFactory"/>. </summary> /// <param name="dbf"> the factory to configure </param> protected internal virtual void configureFactory(DocumentBuilderFactory dbf) { dbf.Validating = true; dbf.IgnoringComments = false; dbf.IgnoringElementContentWhitespace = false; dbf.NamespaceAware = true; protectAgainstXxeAttacks(dbf); }
public void Create_ValidFormat_InvalidCase() { IEnumerable <string> supportedFormats = DocumentBuilderFactory.GetSupportedFormats(); foreach (string format in supportedFormats) { Assert.IsNotNull(DocumentBuilderFactory.Create(format.ToUpper())); } }
protected void read(string file) { try { string rootDir = ""; try { rootDir = getClass().getProtectionDomain().getCodeSource().getLocation().getPath().replace("%20", " "); rootDir = new File(rootDir).getParent(); } catch (Exception e) { //throw e; } file = rootDir + FileUtils.FILE_SEPARATOR + file; DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); Document doc = docBuilder.parse(new File(file)); doc.getDocumentElement().normalize(); NodeList childNodes = doc.getChildNodes(); parameters.clear(); for (int s = 0; s < childNodes.getLength(); s++) { Node item = childNodes.item(s); if (item.getNodeType() == Node.ELEMENT_NODE) { Element element = (Element)item; NodeList tagName = element.getElementsByTagName("port"); parameters.put("port", tagName.item(0).getChildNodes().item(0).getNodeValue().trim()); } } } catch (SAXParseException err) { Console.Out.WriteLine("parsing error"); } catch (ParserConfigurationException e) { Console.Out.WriteLine("configuration error"); } catch (SAXException e) { Console.Out.WriteLine("general sax parser error"); } catch (IOException e) { Console.Out.WriteLine("config file error"); } catch (Exception e) { Console.Out.WriteLine("general parser error"); } }
public static Document Erp90w(string path) { SAXParserFactoryImpl sAXParserFactoryImpl = new SAXParserFactoryImpl(); DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); documentBuilderFactory.setNamespaceAware(true); Document document = documentBuilderFactory.newDocumentBuilder().parse(new BufferedInputStream(new FileInputStream(path))); return(document); }
/// <summary> /// Constructor for the <c>DocumentProvider</c> object. This /// is used to instantiate a parser factory that will be used to /// create parsers when requested. Instantiating the factory up /// front also checks that the framework is fully supported. /// </summary> public DocumentProvider() { this.factory = DocumentBuilderFactory.newInstance(); this.factory.setNamespaceAware(true); }