public virtual void testIsDirty() { XMLDoc doc = new XMLDoc("test", null); KElement e = doc.getRoot(); Assert.IsFalse(e.isDirty()); Assert.IsFalse(doc.isDirty(null)); doc.getCreateXMLDocUserData().setDirtyPolicy(EnumDirtyPolicy.Doc); Assert.IsFalse(e.isDirty()); Assert.IsFalse(doc.isDirty(null)); e.setAttribute("foo", "bar"); Assert.IsTrue(e.isDirty()); Assert.IsTrue(doc.isDirty(null)); doc.clearDirtyIDs(); Assert.IsFalse(doc.isDirty(null)); Assert.IsFalse(e.isDirty()); KElement e2 = e.appendElement("foobar"); Assert.IsTrue(e.isDirty()); Assert.IsTrue(doc.isDirty(null)); Assert.IsTrue(e2.isDirty()); doc.getCreateXMLDocUserData().setDirtyPolicy(EnumDirtyPolicy.XPath); doc.clearDirtyIDs(); Assert.IsFalse(doc.isDirty(null)); Assert.IsFalse(e.isDirty()); e2 = e.appendElement("foobar"); Assert.IsTrue(doc.isDirty(null)); Assert.IsTrue(e.isDirty()); Assert.IsTrue(e2.isDirty()); }
public sheet() { drw = (DrawingDocument)Macros.StandardAddInServer.m_inventorApplication.ActiveDocument; invDoc = new InvDoc.InvDocument <Document>((Document)drw); invDoc.doc = (Document)drw; InitializeComponent(); if (System.IO.File.Exists(@"C:\ProgramData\Autodesk\Inventor Addins\sheet.xml")) { xmlDoc = new XMLDoc(@"C:\ProgramData\Autodesk\Inventor Addins\sheet.xml", "head"); foreach (var item in xmlDoc.Doc.Descendants("w")) { comboBox1.Items.Add(item.Value); } if (comboBox1.Items.Count != 0) { comboBox1.Text = comboBox1.Items[0].ToString(); } foreach (var item in xmlDoc.Doc.Descendants("h")) { comboBox2.Items.Add(item.Value); } if (comboBox2.Items.Count != 0) { comboBox2.Text = comboBox2.Items[0].ToString(); } } }
public void ValidateXmlFormat() { if (XMLDoc == null) { XMLData = "<genxml></genxml>"; // if we don;t have anything, create an empty default to stop errors. } if (XMLDoc.SelectSingleNode("genxml/hidden") == null) { SetXmlProperty("genxml/hidden", ""); } if (XMLDoc.SelectSingleNode("genxml/textbox") == null) { SetXmlProperty("genxml/textbox", ""); } if (XMLDoc.SelectSingleNode("genxml/checkbox") == null) { SetXmlProperty("genxml/checkbox", ""); } if (XMLDoc.SelectSingleNode("genxml/dropdownlist") == null) { SetXmlProperty("genxml/dropdownlist", ""); } if (XMLDoc.SelectSingleNode("genxml/radiobuttonlist") == null) { SetXmlProperty("genxml/radiobuttonlist", ""); } if (XMLDoc.SelectSingleNode("genxml/checkboxlist") == null) { SetXmlProperty("genxml/checkboxlist", ""); } }
public virtual void testContainsElement() { XMLDoc d = new XMLDoc("doc", null); KElement e = d.getRoot(); KElement e1 = e.appendElement("e1"); e1.setAttribute("a", "b"); VElement v = new VElement(); v.appendUnique(e1); e1 = e.appendElement("e1"); e1.setAttribute("a", "b"); Assert.IsTrue(v.containsElement(e1), "containsElement"); Assert.IsFalse(v.Contains(e1), "contains"); e1.setText("foo"); Assert.IsFalse(v.containsElement(e1), "containsElement"); v.appendUnique(e1); Assert.AreEqual(2, v.Count, "size"); e1 = e.appendElement("e1"); e1.setAttribute("a", "b"); e1.setText("foo"); Assert.IsTrue(v.containsElement(e1), "containsElement"); e1.setText("bar"); Assert.IsFalse(v.containsElement(e1), "containsElement"); }
public virtual void testIsEqual() { XMLDoc d = new XMLDoc("doc", null); KElement e = d.getRoot(); KElement e1 = e.appendElement("e1"); e1.setAttribute("a", "b"); KElement e2 = e.appendElement("e1"); e2.setAttribute("a", "c"); KElement e3 = e.appendElement("e1"); e3.setAttribute("a", "c"); KElement e4 = e.appendElement("e1"); e4.setAttribute("a", "d"); VElement v = new VElement(); v.Add(e1); v.Add(e2); VElement v2 = new VElement(v); Assert.IsTrue(v.isEqual(v2)); v2[1] = e3; Assert.IsTrue(v.isEqual(v2)); v2[1] = e4; Assert.IsFalse(v.isEqual(v2)); }
public virtual void testUmlaut() { XMLDoc d = new XMLDoc("doc", null); string dirStr = sm_dirTestDataTemp + @"dir\dir%20 Grün€"; DirectoryInfo dir = new DirectoryInfo(dirStr); if (dir.Exists) { dir.Delete(true); } dir.Create(); // get the directory path string without the relative path stuff (i.e. ..\..\) dirStr = dir.FullName; string fStr = dirStr + @"\7€ .xml"; FileInfo f = new FileInfo(fStr); Assert.IsTrue(d.write2File(fStr, 0, true)); Assert.IsTrue(f.Exists); JDFParser p = new JDFParser(); JDFDoc d2 = p.parseFile(fStr); Assert.IsNotNull(d2); Assert.AreEqual("doc", d2.getRoot().LocalName); }
public virtual void testCreateBig() { for (int ii = 0; ii < 4; ii++) { XMLDoc d = ii % 2 == 0 ? new XMLDoc("foo", null) : new JDFDoc("JDF"); KElement e = d.getRoot(); long l = DateTime.Now.Ticks; for (int j = 0; j < 2000; j++) { KElement e2 = e.appendElement("AuditPool"); KElement e3 = e2.appendElement("Created"); for (int i = 33; i < 199; i++) { if (i < 2) { e3.setAttribute("k" + Convert.ToString(i), "value" + Convert.ToString(i)); } else { e3.setAttributeRaw("k" + Convert.ToString(i), "value" + Convert.ToString(i)); } } } long l2 = DateTime.Now.Ticks; Console.WriteLine("xmldoc create: " + ii + " " + (l2 - l) / 1000000); string fil = sm_dirTestDataTemp + "big" + ii + "writ.jdf"; d.write2File(fil, 2, false); FileInfo f = new FileInfo(fil); long l3 = DateTime.Now.Ticks; Console.WriteLine("xmldoc write: " + ii + " " + (l3 - l2) / 1000000 + " " + f.Length); Console.WriteLine("xmldoc total: " + ii + " " + (l3 - l) / 1000000 + "\n"); } }
public virtual void testWriteToStreamIndent() { XMLDoc d = new XMLDoc("a", null); KElement e = d.getRoot(); KElement b = e.appendElement("b"); ByteArrayIOStream bos = new ByteArrayIOStream(); d.write2Stream(bos, 2, false); string s = System.Text.Encoding.GetEncoding("utf-8").GetString(bos.ToArray()); Assert.IsTrue(s.IndexOf("\n ") > 0); string text = "aa\r\nbb\r\n"; b.setText(text); bos = new ByteArrayIOStream(); d.write2Stream(bos, 2, false); s = System.Text.Encoding.GetEncoding("utf-8").GetString(bos.ToArray()); Assert.IsTrue(s.IndexOf(text) > 0); JDFParser p = new JDFParser(); // JDFDoc dd = p.parseStream(bos.getInputStream()); bos = new ByteArrayIOStream(); d.write2Stream(bos, 2, false); s = System.Text.Encoding.GetEncoding("utf-8").GetString(bos.ToArray()); Assert.IsTrue(s.IndexOf(text) > 0); }
public virtual void testWriteToFileURL() { XMLDoc d = new XMLDoc("doc", null); string dirStr = sm_dirTestDataTemp + @"dir\dir2"; DirectoryInfo dir = new DirectoryInfo(dirStr); if (dir.Exists) { dir.Delete(true); } dir.Create(); // get the directory path string without the relative path stuff (i.e. ..\..\) dirStr = dir.FullName; string fStr1 = dirStr + @"\d .xml"; string fStr2 = dirStr + @"\d%20.xml"; FileInfo f = new FileInfo(fStr1); Assert.IsNotNull(d.write2URL("File:" + fStr1, null)); Assert.IsTrue(f.Exists); Assert.IsNotNull(d.write2URL("File:" + fStr2, null)); Assert.IsTrue(f.Exists); }
public virtual void testNSRoot() { XMLDoc d = new XMLDoc("JDF:foo", null); KElement e = d.getRoot(); Assert.IsFalse(e is JDFElement, "E K"); d = new XMLDoc("a:foo", "bar"); e = d.getRoot(); Assert.IsFalse(e is JDFElement, "E K"); d = new XMLDoc("_foo", null); e = d.getRoot(); Assert.IsFalse(e is JDFElement, "E K"); d = new XMLDoc("bar:foo", JDFConstants.JDFNAMESPACE); e = d.getRoot(); Assert.IsTrue(e is JDFElement, "E K"); d = new XMLDoc("Myfoo", JDFConstants.JDFNAMESPACE); e = d.getRoot(); Assert.IsTrue(e is JDFElement, "E K"); d = new XMLDoc("JDF:Myfoo", JDFConstants.JDFNAMESPACE); e = d.getRoot(); Assert.IsTrue(e is JDFElement, "E K"); d = new XMLDoc("Myfoo", null); e = d.getRoot(); Assert.IsFalse(e is JDFElement, "E K"); }
public virtual void testRegisterClass() { XMLDoc.registerCustomClass("JDFTestType", "org.cip4.jdflib.core.JDFTestType"); XMLDoc.registerCustomClass("fnarf:JDFTestType", "org.cip4.jdflib.core.JDFTestType"); JDFDoc d = new JDFDoc("JDF"); JDFNode n = d.getJDFRoot(); JDFTestType tt = (JDFTestType)n.appendElement("JDFTestType", null); tt.setAttribute("fnarf", 3, null); Assert.IsTrue(tt.isValid(KElement.EnumValidationLevel.Complete), "extension is valid"); tt = (JDFTestType)n.appendElement("fnarf:JDFTestType", "WWW.fnarf.com"); tt.setAttribute("fnarf", 3, null); Assert.IsTrue(tt.isValid(KElement.EnumValidationLevel.Complete), "ns extension is valid"); tt.setAttribute("fnarf", "a", null); // illegal - must be integer Assert.IsTrue(!tt.isValid(KElement.EnumValidationLevel.Complete), "ns extension is valid"); tt.removeAttribute("fnarf", null); Assert.IsTrue(tt.isValid(KElement.EnumValidationLevel.Complete), "ns extension is valid"); tt.setAttribute("gnu", "a", null); // illegal - non existent Assert.IsFalse(tt.isValid(KElement.EnumValidationLevel.Complete), "ns extension is valid"); // boolean bClassCast = false; // try // { // tt = (JDFTestType) n.appendElement("blub:JDFTestType", // "WWW.fnarf2.com"); // } // catch (ClassCastException exc) // { // bClassCast = true; // } // Assert.IsTrue("ns extension works", bClassCast); Assert.IsTrue(!(n.appendElement("blub:JDFTestType", "WWW.fnarf2.com") is JDFTestType), "ns extension works"); }
public virtual void testCreateAttribute() { XMLDoc d = new XMLDoc("TEST", null); XmlAttribute a = d.createAttribute("dom1"); Assert.IsNotNull(a, "a"); bool bcatch = false; try { d.createAttribute("xmlns:foo"); } catch (Exception) { bcatch = true; } Assert.IsTrue(!bcatch, "catch b"); bcatch = false; try { d.createAttribute("foo:dom1"); } catch (Exception) { bcatch = true; } Assert.IsTrue(!bcatch, "catch c"); }
public XMLService() { var kernel = new StandardKernel(); kernel.Load(Assembly.GetExecutingAssembly()); repo = kernel.Get <XMLDoc>(); }
public async Task <ActionResult <XMLDoc> > PostXMLDoc(XMLDoc xMLDoc) { _context.XMLDocs.Add(xMLDoc); await _context.SaveChangesAsync(); return(CreatedAtAction("GetXMLDoc", new { id = xMLDoc.Id }, xMLDoc)); }
public async Task <IActionResult> PutXMLDoc(long id, XMLDoc xMLDoc) { if (id != xMLDoc.Id) { return(BadRequest()); } _context.Entry(xMLDoc).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!XMLDocExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private Dictionary <string, string> AddToDictionary(Dictionary <string, string> inpDictionary, string xpath) { if (XMLDoc != null) { var nods = XMLDoc.SelectNodes(xpath); if (nods != null) { foreach (XmlNode nod in nods) { if (inpDictionary.ContainsKey(nod.Name)) { inpDictionary[nod.Name] = nod.InnerText; // overwrite same name node } else { inpDictionary.Add(nod.Name, nod.InnerText); } if (nod.Attributes != null && nod.Attributes["selectedtext"] != null) { var textname = nod.Name + "text"; if (inpDictionary.ContainsKey(textname)) { inpDictionary[textname] = nod.Attributes["selectedtext"].Value; // overwrite same name node } else { inpDictionary.Add(textname, nod.Attributes["selectedtext"].Value); } } } } } return(inpDictionary); }
public void ValidateXmlFormat() { if (XMLDoc == null) { XMLData = GenXmlFunctions.GetGenXml(new RepeaterItem(0, ListItemType.Item)); // if we don;t have anything, create an empty default to stop errors. } if (XMLDoc.SelectSingleNode("genxml/hidden") == null) { SetXmlProperty("genxml/hidden", ""); } if (XMLDoc.SelectSingleNode("genxml/textbox") == null) { SetXmlProperty("genxml/textbox", ""); } if (XMLDoc.SelectSingleNode("genxml/checkbox") == null) { SetXmlProperty("genxml/checkbox", ""); } if (XMLDoc.SelectSingleNode("genxml/dropdownlist") == null) { SetXmlProperty("genxml/dropdownlist", ""); } if (XMLDoc.SelectSingleNode("genxml/radiobuttonlist") == null) { SetXmlProperty("genxml/radiobuttonlist", ""); } }
/// <summary> /// Replace xml node in NBrightInfo structure /// </summary> /// <param name="strXml">New XML, must be in NBright Strucutre (genxml/...)</param> /// <param name="xPathSource">Source path of the xml, this is for the new node and the old existing node</param> /// <param name="xPathRootDestination">parent node to place the new node onto</param> /// <param name="addNode">add if the node doesn;t already exists.</param> public void ReplaceXmlNode(string strXml, string xPathSource, string xPathRootDestination, bool addNode = true) { var xmlDocNew = new XmlDocument(); xmlDocNew.LoadXml(strXml); var xmlNod = XMLDoc.SelectSingleNode(xPathSource); if (xmlNod != null) { var xmlNod2 = xmlDocNew.SelectSingleNode(xPathSource); if (xmlNod2 != null) { var newNod = XMLDoc.ImportNode(xmlNod2, true); var selectSingleNode = XMLDoc.SelectSingleNode(xPathRootDestination); if (selectSingleNode != null) { selectSingleNode.ReplaceChild(newNod, xmlNod); XMLData = XMLDoc.OuterXml; } } } else { if (addNode) { AddXmlNode(strXml, xPathSource, xPathRootDestination); } } }
public void SetCustomAttribute(string Key, string Value) { try { if (!Convert.ToBoolean(XmlNode.Attributes.GetNamedItem(Key) == null)) { if (Value == null) { XmlNode.Attributes.Remove((XmlAttribute)XmlNode.Attributes.GetNamedItem(Key)); } else { XmlNode.Attributes.GetNamedItem(Key).Value = Value; } } else if (Value != null) { XmlAttribute objAttr = XMLDoc.CreateAttribute(Key); objAttr.Value = Value; XmlNode.Attributes.Append(objAttr); } } catch (Exception ex) { throw (ex); } }
private void Init() { doc = new XMLDoc(AppConstants.SETTINGS_FILE_NAME); txtEncDir.Text = doc.GetValueOf(AppConstants.ENC_DIR); txtDecDir.Text = doc.GetValueOf(AppConstants.DEC_DIR); txtPubKeyDir.Text = doc.GetValueOf(AppConstants.PUBKEY_FILE); }
public void SetCustomAttribute(string key, string value) { try { if ((XmlNode.Attributes.GetNamedItem(key) != null)) { if (value == null) { XmlNode.Attributes.Remove((XmlAttribute)XmlNode.Attributes.GetNamedItem(key)); } else { XmlNode.Attributes.GetNamedItem(key).Value = value; } } else if ((value != null)) { System.Xml.XmlAttribute objAttr = XMLDoc.CreateAttribute(key); objAttr.Value = value; XmlNode.Attributes.Append(objAttr); } } catch (Exception ex) { throw ex; } }
public RecoverOp(Inventor.Document newDoc) { try { invApp = (Inventor.Application)newDoc.Parent; pathFile = newDoc.FullFileName.ToString(); pathFile = pathFile.Substring(0, pathFile.LastIndexOf('\\')); foreach (Document doc in invApp.Documents.VisibleDocuments) { XMLDoc xdoc = new XMLDoc(@"C:\ProgramData\Autodesk\Inventor Addins\rename.xml", "head"); recoverReference(doc, xdoc); } if (newDoc.DocumentType == DocumentTypeEnum.kAssemblyDocumentObject) { m_AsmDoc = (AssemblyDocument)newDoc; recoverAssembly(); tr.End(); } if (newDoc.DocumentType == DocumentTypeEnum.kDrawingDocumentObject) { m_DrwDoc = newDoc as DrawingDocument; recoverDrawing(); } } catch { } finally { tr.End(); } }
public void RemoveXref(string nodeName, string value) { //Removexref node, if there. if (XMLDoc.SelectSingleNode("genxml/" + nodeName + "/id[.='" + value + "']") != null) { RemoveXmlNode("genxml/" + nodeName + "/id[.='" + value + "']"); } }
private void SetFoldersPaths() { XMLDoc doc = new XMLDoc(AppConstants.SETTINGS_FILE_NAME); encrFolder = doc.GetValueOf(AppConstants.ENC_DIR).AppendSlash(); decrFolder = doc.GetValueOf(AppConstants.DEC_DIR).AppendSlash(); pubKeyFile = doc.GetValueOf(AppConstants.PUBKEY_FILE); DisableIfPathsNotSet(); }
public virtual void testCreateElementNoNS() { XMLDoc d = new XMLDoc("TEST", null); d.getMemberDocument().setIgnoreNSDefault(true); KElement e = (KElement)d.createElement("bar"); Assert.IsNull(e.getNamespaceURI() == "" ? null : ""); }
public static XMLDoc LoadXML(Stream inStream) { XMLDoc newData = new XMLDoc(); // newData.Load (inStream); MemoryStream stream = DecryptXml(inStream); newData.Load(stream); stream.Close(); return(newData); }
public static XMLDoc LoadXML(string path, string name) { XMLDoc newData = new XMLDoc(); // newData.Load (path + name); MemoryStream stream = DecryptXml(path + name); newData.Load(stream); stream.Close(); return(newData); }
public List <String> GetXrefList(string nodeName) { var strList = new List <String>(); var nodList = XMLDoc.SelectNodes("genxml/" + nodeName + "/id"); foreach (XmlNode nod in nodList) { strList.Add(nod.InnerText); } return(strList); }
private List <IContentClass> GetContentClasses() { // RQL for listing all content classes of a folder. // One Parameter: Folder Guid: {0} const string LIST_CC_OF_FOLDER = @"<TEMPLATES folderguid=""{0}"" action=""list""/>"; XMLDoc = _project.ExecuteRQL(string.Format(LIST_CC_OF_FOLDER, Guid.ToRQLString())); return((from XmlElement curNode in XMLDoc.GetElementsByTagName("TEMPLATE") select(IContentClass) new ContentClass(_project, curNode)).ToList()); }
public virtual void testCreateElement() { XMLDoc d = new XMLDoc("TEST", null); KElement e = (KElement)d.createElement("foo:bar"); // e.appendElement("bar:foo"); e.setAttribute("foo:at", "1"); e.appendElement("bar2"); d.getRoot().appendChild(e); Assert.AreEqual("1", e.getAttribute("foo:at")); }