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 : ""); }
/// /// * <param name="parser"> </param> /// * <param name="inSource"> </param> /// * <param name="bEraseEmpty"> /// * @return </param> /// private JDFDoc runParser(XmlSourceSupport inSource, bool bEraseEmpty) { JDFDoc doc = new JDFDoc(); try { XmlReaderSettings settings = new XmlReaderSettings(); XmlReader reader = XmlTextReader.Create(inSource.Bytes, settings); base.Load(reader); doc.setMemberDoc((DocumentJDFImpl)this); if (bEraseEmpty) { doc.getRoot().eraseEmptyNodes(true); // cleanup the XML } } catch (StackOverflowException) { m_lastExcept = null; doc = null; } catch (Exception e) { m_lastExcept = e; doc = null; } if (doc != null && m_ErrorHandler != null) { doc.setValidationResult(m_ErrorHandler.getXMLOutput()); m_ErrorHandler.cleanXML(m_SchemaLocation); } if (doc != null) { KElement root = doc.getRoot(); DocumentJDFImpl memberDocument = doc.getMemberDocument(); string namespaceURI = root.getNamespaceURI(); if (namespaceURI == null || !namespaceURI.ToLower().Contains(JDFConstants.CIP4ORG)) { memberDocument.bKElementOnly = true; memberDocument.setIgnoreNSDefault(true); } else { memberDocument.setIgnoreNSDefault(ignoreNSDefault); } } return(doc); }
public virtual void testCopyElement() { JDFDoc d = new JDFDoc("d1"); JDFElement e = (JDFElement)d.getRoot(); JDFDoc d2 = new JDFDoc("d2"); JDFElement e2 = (JDFElement)d2.getRoot(); KElement e3 = e.copyElement(e2, null); JDFParser p = new JDFParser(); JDFDoc dp = p.parseString("<Device xmlns=\"www.CIP4.org/JDFSchema_1_1\"/>"); KElement ep = dp.getRoot(); KElement e4 = e.copyElement(ep, null); Assert.AreEqual(e4.hasAttribute("xmlns"), ep.hasAttribute("xmlns")); Assert.AreEqual(e3.getNamespaceURI(), e.getNamespaceURI()); Assert.IsFalse(d.ToString().IndexOf("xmlns=\"\"") >= 0); }
public virtual void testAppendElement() { JDFDoc d = new JDFDoc("JDF"); KElement r = d.getRoot(); KElement e = r.appendElement("e"); Assert.AreEqual(e.getNamespaceURI(), JDFElement.getSchemaURL()); KElement foo = e.appendElement("pt:foo", "www.pt.com"); Assert.AreEqual("www.pt.com", foo.getNamespaceURI()); KElement bar = foo.appendElement("bar"); Assert.IsNotNull(bar.getNamespaceURI()); KElement foo2 = bar.appendElement("pt:foo", "www.pt.com"); Assert.AreEqual("www.pt.com", foo2.getNamespaceURI()); }
public virtual void testParseNoNS() { XMLDoc d = new XMLDoc("TEST", null); string fn = sm_dirTestDataTemp + "testParseNoNS.xml"; d.write2File(fn, 2, true); JDFParser p = new JDFParser(); JDFDoc d2 = p.parseFile(fn); KElement root = d2.getRoot(); // Assert.IsNull(root.getNamespaceURI()); Assert.IsFalse(d2.ToString().IndexOf("xmlns=\"\"") >= 0); Assert.IsFalse(d.ToString().IndexOf("xmlns=\"\"") >= 0); Assert.IsFalse(root.ToString().IndexOf("xmlns=\"\"") >= 0); KElement foo = root.appendElement("foofoo"); Assert.IsNull(foo.getNamespaceURI() == "" ? null : ""); }