public SetAttributeNode ( |
||
newAttr | ||
return |
protected virtual XmlElement saveToFile(XmlDocument doc, XmlElement root) { XmlAttribute name = doc.CreateAttribute(PetriXmlHelper.XML_BASEITEM_NAMESPACE_PREFIX, "name", PetriXmlHelper.XML_BASEITEM_NAMESPACE); name.Value = this.name; root.SetAttributeNode(name); XmlAttribute unid = doc.CreateAttribute(PetriXmlHelper.XML_BASEITEM_NAMESPACE_PREFIX, "unid", PetriXmlHelper.XML_BASEITEM_NAMESPACE); unid.Value = this.unid.ToString(); root.SetAttributeNode(unid); XmlAttribute showAnnotation = doc.CreateAttribute(PetriXmlHelper.XML_BASEITEM_NAMESPACE_PREFIX, "showannotation", PetriXmlHelper.XML_BASEITEM_NAMESPACE); showAnnotation.Value = this.showAnnotation.ToString(); root.SetAttributeNode(showAnnotation); return root; }
protected XmlElement writeItemData(XmlDocument doc, XmlElement root) { XmlAttribute name = doc.CreateAttribute(PetriXmlHelper.XML_BASEITEM_NAMESPACE_PREFIX, AbstractItem.XML_NAME, PetriXmlHelper.XML_BASEITEM_NAMESPACE); name.Value = this.name; root.SetAttributeNode(name); XmlAttribute unid = doc.CreateAttribute(PetriXmlHelper.XML_BASEITEM_NAMESPACE_PREFIX, AbstractItem.XML_UNID, PetriXmlHelper.XML_BASEITEM_NAMESPACE); unid.Value = this.unid.ToString(); root.SetAttributeNode(unid); XmlAttribute showAnnotation = doc.CreateAttribute(PetriXmlHelper.XML_BASEITEM_NAMESPACE_PREFIX, AbstractItem.XML_SHOWANNOTATION, PetriXmlHelper.XML_BASEITEM_NAMESPACE); showAnnotation.Value = this.showAnnotation.ToString(); root.SetAttributeNode(showAnnotation); return root; }
public static XmlAttribute CreateAndAppendAttribute(XmlElement parent, string name, string value) { XmlAttribute xAttribute = parent.OwnerDocument.CreateAttribute(name); if (value != String.Empty) xAttribute.Value = value; parent.SetAttributeNode(xAttribute); return xAttribute; }
protected override XmlElement saveToFile(XmlDocument doc, XmlElement root) { base.saveToFile(doc, root); XmlAttribute attachedItem = doc.CreateAttribute(PetriXmlHelper.XML_NOTE_NAMESPACE_PREFIX, "attachedItem", PetriXmlHelper.XML_NOTE_NAMESPACE); attachedItem.Value = this.attachedItem.Unid.ToString(); root.SetAttributeNode(attachedItem); XmlElement text = doc.CreateElement(PetriXmlHelper.XML_NOTE_NAMESPACE_PREFIX, "Text", PetriXmlHelper.XML_NOTE_NAMESPACE); text.InnerText = this.text; root.AppendChild(text); return root; }
public void Init() { base.Init(); elementCreator=new GraphConnectorElementCreator(xmiDocument,documentBuilder); parentElement=GraphNodeElementStub.CreateGraphNodeElementStub(xmiDocument); graphEdgeElement=GraphEdgeElementStub.CreateGraphEdgeElementStub(xmiDocument); XmlAttribute idAttr=xmiDocument.CreateAttribute("xmi","id",XmiElements.XMI_NAMESPACE_URI); idAttr.Value=GRAPH_EDGE_ELEMENT_ID; graphEdgeElement.SetAttributeNode(idAttr); //graphEdgeElement.SetAttribute(XmiElements.XMI_ID_ATTR_NAME,XmiElements.XMI_NAMESPACE_URI,GRAPH_EDGE_ELEMENT_ID); }
public XmlAttribute AddAttributeNode(XmlElement node, string name, string value) { XmlAttribute a = xmlDoc.CreateAttribute(name); a.Value = value; if (node == null) xmlDoc.DocumentElement.SetAttributeNode(a); else node.SetAttributeNode(a); return a; }
protected override XmlElement saveToFile(XmlDocument doc, XmlElement root) { base.saveToFile(doc, root); root.AppendChild(PetriXmlHelper.savePointF(doc, this.point, "TopLeftPoint")); root.AppendChild(PetriXmlHelper.savePointF(doc, this.origo, "Origo")); root.AppendChild(PetriXmlHelper.savePointF(doc, this.labelOffset, "LabelOffset")); root.AppendChild(PetriXmlHelper.saveSizeF(doc, this.size, "Size")); XmlAttribute radius = doc.CreateAttribute(PetriXmlHelper.XML_ITEM_NAMESPACE_PREFIX, "radius", PetriXmlHelper.XML_ITEM_NAMESPACE); radius.Value = this.radius.ToString(); root.SetAttributeNode(radius); return root; }
protected override XmlElement saveToFile(XmlDocument doc, XmlElement root) { base.saveToFile(doc, root); root.AppendChild(PetriXmlHelper.savePointF(doc, this.clockOffset, "ClockOffset")); XmlAttribute angle = doc.CreateAttribute(PetriXmlHelper.XML_TRANSITION_NAMESPACE_PREFIX, "angle", PetriXmlHelper.XML_TRANSITION_NAMESPACE); angle.Value = this.angle.ToString(); root.SetAttributeNode(angle); XmlAttribute priority = doc.CreateAttribute(PetriXmlHelper.XML_TRANSITION_NAMESPACE_PREFIX, "priority", PetriXmlHelper.XML_TRANSITION_NAMESPACE); priority.Value = this.priority.ToString(); root.SetAttributeNode(priority); XmlAttribute transitionType = doc.CreateAttribute(PetriXmlHelper.XML_TRANSITION_NAMESPACE_PREFIX, "type", PetriXmlHelper.XML_TRANSITION_NAMESPACE); transitionType.Value = this.transitionType.Value; root.SetAttributeNode(transitionType); XmlAttribute delay = doc.CreateAttribute(PetriXmlHelper.XML_TRANSITION_NAMESPACE_PREFIX, "delay", PetriXmlHelper.XML_TRANSITION_NAMESPACE); delay.Value = this.delay.ToString(); root.SetAttributeNode(delay); XmlAttribute clockRadius = doc.CreateAttribute(PetriXmlHelper.XML_TRANSITION_NAMESPACE_PREFIX, "clockRadius", PetriXmlHelper.XML_TRANSITION_NAMESPACE); clockRadius.Value = this.clockRadius.ToString(); root.SetAttributeNode(clockRadius); return root; }
internal static void AddNamespaces(XmlElement elem, Hashtable namespaces) { if (namespaces != null) { foreach (string str in namespaces.Keys) { if (!elem.HasAttribute(str)) { XmlAttribute newAttr = elem.OwnerDocument.CreateAttribute(str); newAttr.Value = namespaces[str] as string; elem.SetAttributeNode(newAttr); } } } }
internal static void AddNamespaces(XmlElement elem, CanonicalXmlNodeList namespaces) { if (namespaces != null) { foreach (XmlNode node in namespaces) { string name = (node.Prefix.Length > 0) ? (node.Prefix + ":" + node.LocalName) : node.LocalName; if (!elem.HasAttribute(name) && (!name.Equals("xmlns") || (elem.Prefix.Length != 0))) { XmlAttribute newAttr = elem.OwnerDocument.CreateAttribute(name); newAttr.Value = node.Value; elem.SetAttributeNode(newAttr); } } } }
/// <summary> /// Used by CompressXML /// </summary> /// <param name="counts">Map of attribute to number of occurrences -- could be used to improve algorithm</param> /// <param name="entities">Map of attribute to entity name</param> /// <param name="doc"></param> /// <param name="el"></param> /// <param name="idx">Number that is incremented to provide new entity names</param> private static void RecCompXML(Hashtable counts, Hashtable entities, XmlDocument doc, XmlElement el, ref int idx) { ArrayList keys = new ArrayList(); foreach(XmlAttribute att in el.Attributes) { //don't try to do anything with xmlns nodes. if (att.Name.IndexOf("xmlns") == -1) keys.Add(att.Name); } foreach(string s in keys) { string val = el.Attributes[s].Value; if (counts[val] == null) { counts[val] = 1; } else { counts[val] = (int)counts[val] + 1; } if (val.Length > 30) { string entname; if(entities[val] == null) { idx += 1; entname = "E"+idx.ToString(); entities[val] = entname; } else { entname = (string)entities[val]; } XmlAttribute attr; //xlinks are a special case at the moment as the .NET XML API requires whatever bit of code //outputs a qualified name to *just magically happen to know* the URI that the prefix refers to. if (s.IndexOf("xlink") == 0) { attr = doc.CreateAttribute(s, "http://www.w3.org/1999/xlink"); } else { attr = doc.CreateAttribute(s); } attr.AppendChild(doc.CreateEntityReference(entname)); el.SetAttributeNode(attr); } } foreach(XmlNode ch in el.ChildNodes) { if (ch.GetType() == typeof(XmlElement)) RecCompXML(counts, entities, doc, (XmlElement)ch, ref idx); } }
internal static void AddNamespaces (XmlElement elem, CanonicalXmlNodeList namespaces) { if (namespaces != null) { foreach (XmlNode attrib in namespaces) { string name = ((attrib.Prefix.Length > 0) ? attrib.Prefix + ":" + attrib.LocalName : attrib.LocalName); // Skip the attribute if one with the same qualified name already exists if (elem.HasAttribute(name) || (name.Equals("xmlns") && elem.Prefix.Length == 0)) continue; XmlAttribute nsattrib = (XmlAttribute) elem.OwnerDocument.CreateAttribute(name); nsattrib.Value = attrib.Value; elem.SetAttributeNode(nsattrib); } } }
internal static void AddNamespaces (XmlElement elem, Hashtable namespaces) { if (namespaces != null) { foreach (string key in namespaces.Keys) { if (elem.HasAttribute(key)) continue; XmlAttribute nsattrib = (XmlAttribute) elem.OwnerDocument.CreateAttribute(key); nsattrib.Value = namespaces[key] as string; elem.SetAttributeNode(nsattrib); } } }
private void SetAttribute(XmlElement element, string nsuri, string prefix, string localname, string val) { XmlAttribute attr = doc.CreateAttribute(prefix, localname, nsuri); attr.Value = val; element.SetAttributeNode(attr); }
private void FillNodeChildrenFromRow (DataRow row, XmlElement element) { DataTable table = row.Table; // fill columns for the row for (int i = 0; i < table.Columns.Count; i++) { DataColumn col = table.Columns [i]; string value = row.IsNull (col) ? String.Empty : row [col].ToString (); switch (col.ColumnMapping) { case MappingType.Element: XmlElement el = CreateElement (col.Prefix, XmlHelper.Encode (col.ColumnName), col.Namespace); el.InnerText = value; element.AppendChild (el); break; case MappingType.Attribute: XmlAttribute attr = CreateAttribute (col.Prefix, XmlHelper.Encode (col.ColumnName), col.Namespace); attr.Value = value; element.SetAttributeNode (attr); break; case MappingType.SimpleContent: XmlText text = CreateTextNode (value); element.AppendChild (text); break; // FIXME: how to handle hidden? } } }
private XmlAttribute GetTargetNodeAttribute(XmlElement trgNode, string attName) { var att = trgNode.Attributes[attName]; if (att == null) { att = _targetXmlDoc.CreateAttribute(attName); trgNode.SetAttributeNode(att); } return att; }
internal void AddDefaultAttributes(XmlElement elem) { System.Xml.Schema.SchemaInfo dtdSchemaInfo = this.DtdSchemaInfo; SchemaElementDecl schemaElementDecl = this.GetSchemaElementDecl(elem); if ((schemaElementDecl != null) && (schemaElementDecl.AttDefs != null)) { IDictionaryEnumerator enumerator = schemaElementDecl.AttDefs.GetEnumerator(); while (enumerator.MoveNext()) { SchemaAttDef attdef = (SchemaAttDef) enumerator.Value; if ((attdef.Presence == SchemaDeclBase.Use.Default) || (attdef.Presence == SchemaDeclBase.Use.Fixed)) { string attrPrefix = string.Empty; string name = attdef.Name.Name; string attrNamespaceURI = string.Empty; if (dtdSchemaInfo.SchemaType == SchemaType.DTD) { attrPrefix = attdef.Name.Namespace; } else { attrPrefix = attdef.Prefix; attrNamespaceURI = attdef.Name.Namespace; } XmlAttribute newAttr = this.PrepareDefaultAttribute(attdef, attrPrefix, name, attrNamespaceURI); elem.SetAttributeNode(newAttr); } } } }
protected XmlDocument _GetComponentsXmlDoc(out XmlElement topNode) { string sSchemaFilePath = this._DisplayComponentsSchemaPath; bool bValidSchemaPath = false; bValidSchemaPath = Path.HasExtension(sSchemaFilePath); if (bValidSchemaPath) { using (XmlReader schemaXSD = this.GetXSD(sSchemaFilePath)) { if (schemaXSD == null) { throw new System.IO.FileNotFoundException("File does not exist.", sSchemaFilePath); } } } if (!bValidSchemaPath) { throw new System.ArgumentException("Invalid schema path."); } XmlDocument doc = new XmlDocument(); XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", String.Empty); doc.AppendChild(declaration); XmlNamespaceManager namespaceManager = new XmlNamespaceManager(doc.NameTable); namespaceManager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); // Create top node element topNode = doc.CreateElement(XmlSchemaConstants.Display.sComponent + "s");//"Components" // Add schema information to top node. XmlAttribute schema = doc.CreateAttribute("xsi", "noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance"); schema.Value = this._DisplayComponentsSchemaPath; topNode.SetAttributeNode(schema); doc.AppendChild(topNode); return doc; }//_GetComponentsXmlDoc
XmlNode ReadNodeCore(XmlReader reader) { switch (reader.ReadState) { case ReadState.Interactive: break; case ReadState.Initial: #if NET_2_0 if (reader.SchemaInfo != null) { this.SchemaInfo = new XmlSchemaInfo(reader.SchemaInfo); } #endif reader.Read(); break; default: return(null); } XmlNode n; switch (reader.NodeType) { case XmlNodeType.Attribute: string localName = reader.LocalName; string ns = reader.NamespaceURI; n = ReadAttributeNode(reader); // Keep the current reader position on attribute. reader.MoveToAttribute(localName, ns); return(n); case XmlNodeType.CDATA: n = CreateCDataSection(reader.Value); break; case XmlNodeType.Comment: n = CreateComment(reader.Value); break; case XmlNodeType.Element: XmlElement element = CreateElement(reader.Prefix, reader.LocalName, reader.NamespaceURI, reader.NameTable == this.NameTable); #if NET_2_0 if (reader.SchemaInfo != null) { SchemaInfo = new XmlSchemaInfo(reader.SchemaInfo); } #endif element.IsEmpty = reader.IsEmptyElement; // set the element's attributes. for (int i = 0; i < reader.AttributeCount; i++) { reader.MoveToAttribute(i); element.SetAttributeNode( ReadAttributeNode(reader)); reader.MoveToElement(); } // FIXME: the code below should be fine and // in some XmlReaders it is much faster, but // caused some breakage in sys.data test. /* * if (reader.MoveToFirstAttribute ()) { * do { * element.SetAttributeNode (ReadAttributeNode (reader)); * } while (reader.MoveToNextAttribute ()); * reader.MoveToElement (); * } */ reader.MoveToElement(); int depth = reader.Depth; if (reader.IsEmptyElement) { n = element; break; } reader.Read(); while (reader.Depth > depth) { n = ReadNodeCore(reader); if (preserveWhitespace || n.NodeType != XmlNodeType.Whitespace) { element.AppendChild(n, false); } } n = element; break; case XmlNodeType.ProcessingInstruction: n = CreateProcessingInstruction(reader.Name, reader.Value); break; case XmlNodeType.Text: n = CreateTextNode(reader.Value); break; case XmlNodeType.XmlDeclaration: n = CreateXmlDeclaration("1.0", String.Empty, String.Empty); n.Value = reader.Value; break; case XmlNodeType.DocumentType: DTDObjectModel dtd = null; IHasXmlParserContext ctxReader = reader as IHasXmlParserContext; if (ctxReader != null) { dtd = ctxReader.ParserContext.Dtd; } if (dtd != null) { n = CreateDocumentType(dtd); } else { n = CreateDocumentType(reader.Name, reader ["PUBLIC"], reader ["SYSTEM"], reader.Value); } break; case XmlNodeType.EntityReference: if (this.loadMode && this.DocumentType != null && DocumentType.Entities.GetNamedItem(reader.Name) == null) { throw new XmlException("Reference to undeclared entity was found."); } n = CreateEntityReference(reader.Name); // IF argument XmlReader can resolve entity, // ReadNode() also fills children _from it_. // In this case, it is not from doctype node. // (it is kind of sucky design, but it happens // anyways when we modify doctype node). // // It does not happen when !CanResolveEntity. // (In such case AppendChild() will resolve // entity content, as XmlEntityReference does.) if (reader.CanResolveEntity) { reader.ResolveEntity(); reader.Read(); for (XmlNode child; reader.NodeType != XmlNodeType.EndEntity && (child = ReadNode(reader)) != null;) { n.InsertBefore(child, null, false, false); } } break; case XmlNodeType.SignificantWhitespace: n = CreateSignificantWhitespace(reader.Value); break; case XmlNodeType.Whitespace: n = CreateWhitespace(reader.Value); break; case XmlNodeType.None: return(null); default: // No idea why MS does throw NullReferenceException ;-P throw new NullReferenceException("Unexpected node type " + reader.NodeType + "."); } reader.Read(); return(n); }
internal void AddDefaultAttributes( XmlElement elem ) { SchemaInfo schInfo = DtdSchemaInfo; SchemaElementDecl ed = GetSchemaElementDecl( elem ); if ( ed != null && ed.AttDefs != null ) { IDictionaryEnumerator attrDefs = ed.AttDefs.GetEnumerator(); while ( attrDefs.MoveNext() ) { SchemaAttDef attdef = (SchemaAttDef)attrDefs.Value; if ( attdef.Presence == SchemaDeclBase.Use.Default || attdef.Presence == SchemaDeclBase.Use.Fixed ) { //build a default attribute and return string attrPrefix = string.Empty; string attrLocalname = attdef.Name.Name; string attrNamespaceURI = string.Empty; if ( schInfo.SchemaType == SchemaType.DTD ) attrPrefix = attdef.Name.Namespace; else { attrPrefix = attdef.Prefix; attrNamespaceURI = attdef.Name.Namespace; } XmlAttribute defattr = PrepareDefaultAttribute( attdef, attrPrefix, attrLocalname, attrNamespaceURI ); elem.SetAttributeNode( defattr ); } } } }
/// <summary> /// Create a new attribute given an XmlElement (XmlNode) target /// </summary> public XmlAttribute CreateNodeAttribute(XmlElement targetElement, string sAttributeName, string sAttributeValue) { XmlAttribute newAttr = null; try { newAttr = m_xmlDocument.CreateAttribute(sAttributeName); targetElement.SetAttributeNode(newAttr); targetElement.SetAttribute(sAttributeName, "", Encode(sAttributeValue)); } catch (Exception e) { HandleException(e); } return newAttr; }
}//_GetXmlDoc_Validation protected XmlDocument _GetXmlDoc_Validation(out XmlElement configElement, string schemaFilePath) { bool bValidSchemaPath = false; bValidSchemaPath = Path.HasExtension(schemaFilePath); if (bValidSchemaPath) { using (XmlReader schemaXSD = this.GetXSD(schemaFilePath)) { if (schemaXSD == null) { throw new System.IO.FileNotFoundException("File does not exist.", schemaFilePath); } } } if (!bValidSchemaPath) { throw new System.ArgumentException("Invalid schema path."); } XmlDocument doc = new XmlDocument(); XmlDeclaration declaration = doc.CreateXmlDeclaration("1.0", "UTF-8", String.Empty); doc.AppendChild(declaration); XmlNamespaceManager namespaceManager = new XmlNamespaceManager(doc.NameTable); namespaceManager.AddNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance"); // Create root element using 'configuration' variable. //configElement = doc.CreateElement(this.Configuration); configElement = doc.CreateElement(Root); // Add schema information to root. XmlAttribute schema = doc.CreateAttribute("xsi", "noNamespaceSchemaLocation", "http://www.w3.org/2001/XMLSchema-instance"); schema.Value = schemaFilePath; configElement.SetAttributeNode(schema); doc.AppendChild(configElement); return doc; }//_GetXmlDoc_Validation
/// <summary> /// Used by CompressXML /// </summary> /// <param name="counts">Map of attribute to number of occurrences -- could be used to improve algorithm</param> /// <param name="entities">Map of attribute to entity name</param> /// <param name="doc"></param> /// <param name="el"></param> /// <param name="idx">Number that is incremented to provide new entity names</param> private static void RecCompXML(Hashtable counts, Hashtable entities, XmlDocument doc, XmlElement el, ref int idx) { ArrayList keys = new ArrayList(); foreach(XmlAttribute att in el.Attributes) { keys.Add(att.Name); } foreach(string s in keys) { string val = el.Attributes[s].Value; if (counts[val] == null) { counts[val] = 1; } else { counts[val] = (int)counts[val] + 1; } if (val.Length > 30) { string entname; if(entities[val] == null) { idx += 1; entname = "E"+idx.ToString(); entities[val] = entname; } else { entname = (string)entities[val]; } XmlAttribute attr = doc.CreateAttribute(s); attr.AppendChild(doc.CreateEntityReference(entname)); el.SetAttributeNode(attr); } } foreach(XmlNode ch in el.ChildNodes) { if (ch.GetType() == typeof(XmlElement)) RecCompXML(counts, entities, doc, (XmlElement)ch, ref idx); } }
private static void CheckAttribute(XmlElement xmlElement, string attrName, string attrDefaultValue) { XmlAttribute atr = xmlElement.GetAttributeNode(attrName); if (atr == null) xmlElement.SetAttributeNode(attrName, xmlElement.BaseURI).Value = attrDefaultValue; else if (string.IsNullOrEmpty(atr.Value)) atr.Value = attrDefaultValue; }
/// <summary> /// Записывает заголовок Xml документа. /// </summary> static private void WriteHeaders() { //Заголовки: document.AppendChild(document.CreateXmlDeclaration("1.0", null, null)); document.AppendChild(document.CreateProcessingInstruction("mso-application", "progid='Excel.Sheet'")); workbook = document.CreateElement("s", "Workbook", spreadsheetNamespace); XmlAttribute ns1 = document.CreateAttribute("xmlns:x", htmlNamespace); ns1.Value = excelNamespace; workbook.SetAttributeNode(ns1); XmlAttribute ns2 = document.CreateAttribute("xmlns:o", htmlNamespace); ns2.Value = officeNamespace; workbook.SetAttributeNode(ns2); document.AppendChild(workbook); }
//Creates a XML-Document with namespaces, testsubject, testergroup public void createEmptyEarlGraph(MediaType chosenMediaType) { this.mediaType = chosenMediaType; string baseDir = AppDomain.CurrentDomain.BaseDirectory; baseUri = "XMLFile1.xml"; earl = new XmlDocument(); XmlDeclaration xdeclaration = earl.CreateXmlDeclaration("1.0", "utf-8", null); nsmgr = new XmlNamespaceManager(earl.NameTable); nsmgr.AddNamespace("rdf", "http://www.w3.org/1999/02/22-rdf-syntax-ns#"); nsmgr.AddNamespace("rdfs", "http://www.w3.org/2000/01/rdf-schema#"); nsmgr.AddNamespace("xsd", "http://www.w3.org/2001/XMLSchema#"); nsmgr.AddNamespace("xml", "http://www.w3.org/XML/1998/namespace"); nsmgr.AddNamespace("dc", "http://purl.org/dc/elements/1.1/"); nsmgr.AddNamespace("earl", "http://www.w3.org/ns/earl#"); nsmgr.AddNamespace("foaf", "http://xmlns.com/foaf/spec/"); nsmgr.AddNamespace("dct", "http://purl.org/dc/terms/"); nsmgr.AddNamespace("doap", "http://usefulinc.com/ns/doap#"); XmlDocumentType doctype; doctype = earl.CreateDocumentType("rdf:RDF", null, null, @" <!ENTITY rdf 'http://www.w3.org/1999/02/22-rdf-syntax-ns#'> <!ENTITY rdfs 'http://www.w3.org/2000/01/rdf-schema#'> <!ENTITY xsd 'http://www.w3.org/2001/XMLSchema#'> <!ENTITY xml 'http://www.w3.org/XML/1998/namespace'> <!ENTITY dc 'http://purl.org/dc/elements/1.1/'> <!ENTITY earl 'http://www.w3.org/ns/earl#'> <!ENTITY foaf 'http://xmlns.com/foaf/spec/'> <!ENTITY dct 'http://purl.org/dc/terms/'> <!ENTITY doap 'http://usefulinc.com/ns/doap#'>"); earl.AppendChild(doctype); root = earl.CreateElement("rdf", "RDF", nsmgr.LookupNamespace("rdf")); foreach (String prefix in nsmgr) { if (!String.IsNullOrWhiteSpace(prefix) && !prefix.Equals("xmlns") ) { var uri = nsmgr.LookupNamespace(prefix); if (!String.IsNullOrWhiteSpace(uri)) root.SetAttribute("xmlns:" + prefix, uri); } } earl.AppendChild(root); software2 = earl.CreateElement("earl", "Software", nsmgr.LookupNamespace("earl")); software2.SetAttributeNode("ID", nsmgr.LookupNamespace("rdf")); software2.SetAttribute("ID", "pruefdialog"); root.AppendChild(software2); XmlElement desc = earl.CreateElement("dct", "description", nsmgr.LookupNamespace("dct")); desc.AppendChild(earl.CreateTextNode("Ein Dialog zur Bewertung taktiler Grafiken")); desc.SetAttributeNode("lang", nsmgr.LookupNamespace("xml")); desc.SetAttribute("lang", "de"); software2.AppendChild(desc); XmlElement title = earl.CreateElement("dct", "title", nsmgr.LookupNamespace("dct")); title.AppendChild(earl.CreateTextNode("Pruefdialog taktile Grafiken")); title.SetAttributeNode("lang", nsmgr.LookupNamespace("xml")); title.SetAttribute("lang", "de"); software2.AppendChild(title); testPerson = earl.CreateElement("foaf", "Person", nsmgr.LookupNamespace("foaf")); testPerson.SetAttributeNode("ID", nsmgr.LookupNamespace("rdf")); testPerson.SetAttribute("ID", "testperson"); XmlElement name = earl.CreateElement("foaf", "name", nsmgr.LookupNamespace("foaf")); name.AppendChild(earl.CreateTextNode("Max Mustermann")); testPerson.AppendChild(name); group = earl.CreateElement("foaf", "Group", nsmgr.LookupNamespace("foaf")); group.SetAttributeNode("ID", nsmgr.LookupNamespace("rdf")); group.SetAttribute("ID", "assertorgroup"); root.AppendChild(group); //TODOOOOOOOO!!!! XmlElement descgroup = earl.CreateElement("dct", "title", nsmgr.LookupNamespace("dct")); descgroup.AppendChild(earl.CreateTextNode("Max Mustermann und Pruefdialog")); group.AppendChild(descgroup); XmlElement descAssertorGroup = earl.CreateElement("dct", "description", nsmgr.LookupNamespace("dct")); descAssertorGroup.AppendChild(earl.CreateTextNode("Max Mustermann überprüfte die Grafik manuell mit dem Pruefdialog")); group.AppendChild(descAssertorGroup); XmlElement mainAssertor = earl.CreateElement("earl", "mainAssertor", nsmgr.LookupNamespace("earl")); mainAssertor.SetAttributeNode("resource", nsmgr.LookupNamespace("rdf")); mainAssertor.SetAttribute("resource", "#"+software2.GetAttribute("ID")); group.AppendChild(mainAssertor); XmlElement foafMember = earl.CreateElement("foaf", "member", nsmgr.LookupNamespace("foaf")); group.AppendChild(foafMember); foafMember.AppendChild(testPerson); testsubject = earl.CreateElement("earl", "TestSubject", nsmgr.LookupNamespace("earl")); testsubject.SetAttributeNode("ID", nsmgr.LookupNamespace("rdf")); testsubject.SetAttribute("ID", "testsubject"); root.AppendChild(testsubject); XmlElement bildTitle = earl.CreateElement("dct", "title", nsmgr.LookupNamespace("dct")); bildTitle.AppendChild(earl.CreateTextNode("Titel der Grafik")); bildTitle.SetAttributeNode("lang", nsmgr.LookupNamespace("xml")); bildTitle.SetAttribute("lang", "de"); testsubject.AppendChild(bildTitle); XmlElement mediaType = earl.CreateElement("dct", "description", nsmgr.LookupNamespace("dct")); mediaType.AppendChild(earl.CreateTextNode("Die geprüfte Grafik"+"(Medium_"+ chosenMediaType.ToString().Normalize() +")" )); testsubject.AppendChild(mediaType); }
private void FixupNamespaceNodes (XmlElement src, XmlElement dst, bool ignoreDefault) { // add namespace nodes foreach (XmlAttribute attr in src.SelectNodes ("namespace::*")) { if (attr.LocalName == "xml") continue; if (ignoreDefault && attr.LocalName == "xmlns") continue; dst.SetAttributeNode (dst.OwnerDocument.ImportNode (attr, true) as XmlAttribute); } }
private void SortAttributesAttributes (XmlElement el) { ArrayList al = new ArrayList (); foreach (XmlAttribute a in el.Attributes) al.Add (a.Name); al.Sort (); string [] names = (string []) al.ToArray (typeof (string)); al.Clear (); foreach (string name in names) al.Add (el.RemoveAttributeNode ( el.GetAttributeNode (name))); foreach (XmlAttribute a in al) // Exclude xmlns="" here. if (a.Name != "xmlns")// || a.Value != String.Empty) el.SetAttributeNode (a); }
void CreateReference (Signature sig, XmlElement el, string id) { CreateReference (sig, el.OwnerDocument, id); if (el.GetAttribute ("Id", Constants.WsuNamespace) != id) { XmlAttribute a = el.SetAttributeNode ("Id", Constants.WsuNamespace); a.Prefix = "u"; a.Value = id; } }
/// <summary> /// Add a Namespace composed of a prefix and a URI to the node /// </summary> /// <param name="node"></param> /// <param name="localName">Prefix associated of this namespace</param> /// <param name="namespaceURI">URI associated of this namespace</param> static public void AddNamespace(this XmlElement node, string localName, string namespaceURI) { node.SetAttributeNode(localName, namespaceURI); }
public virtual XmlNode ImportNode(XmlNode node, bool deep) { if (node == null) { throw new NullReferenceException("Null node cannot be imported."); } switch (node.NodeType) { case XmlNodeType.Attribute: XmlAttribute srcAtt = node as XmlAttribute; XmlAttribute dstAtt = this.CreateAttribute(srcAtt.Prefix, srcAtt.LocalName, srcAtt.NamespaceURI); for (XmlNode n = srcAtt.FirstChild; n != null; n = n.NextSibling) { dstAtt.AppendChild(this.ImportNode(n, deep)); } return(dstAtt); case XmlNodeType.CDATA: return(this.CreateCDataSection(node.Value)); case XmlNodeType.Comment: return(this.CreateComment(node.Value)); case XmlNodeType.Document: throw new XmlException("Document cannot be imported."); case XmlNodeType.DocumentFragment: XmlDocumentFragment df = this.CreateDocumentFragment(); if (deep) { for (XmlNode n = node.FirstChild; n != null; n = n.NextSibling) { df.AppendChild(this.ImportNode(n, deep)); } } return(df); case XmlNodeType.DocumentType: throw new XmlException("DocumentType cannot be imported."); case XmlNodeType.Element: XmlElement src = (XmlElement)node; XmlElement dst = this.CreateElement(src.Prefix, src.LocalName, src.NamespaceURI); for (int i = 0; i < src.Attributes.Count; i++) { XmlAttribute attr = src.Attributes [i]; if (attr.Specified) // copies only specified attributes { dst.SetAttributeNode((XmlAttribute)this.ImportNode(attr, deep)); } } if (deep) { for (XmlNode n = src.FirstChild; n != null; n = n.NextSibling) { dst.AppendChild(this.ImportNode(n, deep)); } } return(dst); case XmlNodeType.EndElement: throw new XmlException("Illegal ImportNode call for NodeType.EndElement"); case XmlNodeType.EndEntity: throw new XmlException("Illegal ImportNode call for NodeType.EndEntity"); case XmlNodeType.EntityReference: return(this.CreateEntityReference(node.Name)); case XmlNodeType.None: throw new XmlException("Illegal ImportNode call for NodeType.None"); case XmlNodeType.ProcessingInstruction: XmlProcessingInstruction pi = node as XmlProcessingInstruction; return(this.CreateProcessingInstruction(pi.Target, pi.Data)); case XmlNodeType.SignificantWhitespace: return(this.CreateSignificantWhitespace(node.Value)); case XmlNodeType.Text: return(this.CreateTextNode(node.Value)); case XmlNodeType.Whitespace: return(this.CreateWhitespace(node.Value)); case XmlNodeType.XmlDeclaration: XmlDeclaration srcDecl = node as XmlDeclaration; return(this.CreateXmlDeclaration(srcDecl.Version, srcDecl.Encoding, srcDecl.Standalone)); default: throw new InvalidOperationException("Cannot import specified node type: " + node.NodeType); } }
// Used by the ReadNode method for recursively building a DOM subtree. internal XmlNode ReadNodeInternal(XmlReader r) { switch (r.NodeType) { case XmlNodeType.Attribute: { // create the attribute XmlAttribute att = CreateAttribute (r.Prefix, r.LocalName, r.NamespaceURI); // read and append the children ReadChildren(r, att); // return the attribute return(att); } // Not reached. case XmlNodeType.CDATA: { // create the character data section XmlCDataSection cdata = CreateCDataSection(r.Value); // advance the reader to the next node r.Read(); // return the character data section return(cdata); } // Not reached. case XmlNodeType.Comment: { // create the comment XmlComment comment = CreateComment(r.Value); // advance the reader to the next node r.Read(); // return the comment return(comment); } // Not reached. case XmlNodeType.DocumentType: { // create the document type XmlDocumentType doctype = CreateDocumentType (r.Name, r["PUBLIC"], r["SYSTEM"], r.Value); // advance the reader to the next node r.Read(); // return the document type return(doctype); } // Not reached. case XmlNodeType.Element: { // create the element XmlElement elem = CreateElement (r.Prefix, r.LocalName, r.NamespaceURI); bool isEmptyElement = r.IsEmptyElement; // read the attributes while (r.MoveToNextAttribute()) { XmlAttribute att = (XmlAttribute)ReadNodeInternal(r); elem.SetAttributeNode(att); } r.MoveToElement(); // return now if there are no children if (isEmptyElement) { // advance the reader to the next node r.Read(); // return the empty element return(elem); } elem.IsEmpty = isEmptyElement; // read and append the children ReadChildren(r, elem); // return the element return(elem); } // Not reached. case XmlNodeType.DocumentFragment: case XmlNodeType.EndElement: case XmlNodeType.EndEntity: case XmlNodeType.Entity: case XmlNodeType.Notation: { // TODO // advance the reader to the next node r.Read(); // nothing to return return(null); } // Not reached. case XmlNodeType.EntityReference: { // create the entity reference XmlEntityReference er = CreateEntityReference(r.Name); // advance the reader to the next node r.Read(); // return the entity reference return(er); } // Not reached. case XmlNodeType.ProcessingInstruction: { // create the processing instruction XmlProcessingInstruction pi = CreateProcessingInstruction (r.Name, r.Value); // advance the reader to the next node r.Read(); // return the processing instruction return(pi); } // Not reached. case XmlNodeType.SignificantWhitespace: { // create the significant whitespace XmlSignificantWhitespace sws = CreateSignificantWhitespace (r.Value); // advance the reader to the next node r.Read(); // return the significant whitespace return(sws); } // Not reached. case XmlNodeType.Text: { // create the text XmlText text = CreateTextNode(r.Value); // advance the reader to the next node r.Read(); // return the text return(text); } // Not reached. case XmlNodeType.Whitespace: { // if whitespace preservation is off, skip whitespace if (!preserveWhitespace) { while (r.Read()) { if (r.NodeType != XmlNodeType.Whitespace) { return(null); } } return(null); } // create the whitespace XmlWhitespace ws = CreateWhitespace(r.Value); // advance the reader to the next node r.Read(); // return the whitespace return(ws); } // Not reached. case XmlNodeType.XmlDeclaration: { // set up the defaults String e = String.Empty; String s = String.Empty; // read the version r.MoveToNextAttribute(); // read the optional attributes if (r.MoveToNextAttribute()) { if (r.Name == "encoding") { e = r.Value; if (r.MoveToNextAttribute()) { s = r.Value; } } else { s = r.Value; } } // create the xml declaration XmlDeclaration xml = CreateXmlDeclaration("1.0", e, s); // advance the reader to the next node r.Read(); // return the xml declaration return(xml); } // Not reached. default: { throw new InvalidOperationException(/* TODO */); } // Not reached. } }
/// <exclude/> protected void AddBaseData(XmlElement element) { XmlDocument doc = element.OwnerDocument; XmlAttribute attrStep = doc.CreateAttribute("stepNumber"); attrStep.Value = stepNumber.ToString(CultureInfo.CurrentUICulture); element.SetAttributeNode(attrStep); XmlAttribute attrProc = doc.CreateAttribute("processName"); attrProc.Value = (procName == "<init>") ? "" : procName; element.SetAttributeNode(attrProc); }
private void CreateAttribute(XmlDocument doc, XmlElement elem, string name, string value){ XmlAttribute attribute = doc.CreateAttribute(name); elem.SetAttributeNode(attribute); elem.SetAttribute(name, value); }