أسلوب createElementNS() في XML DOM

Document Object Reference Manual

التعريف والاستخدام

يمكن لأسلوب createElementNS() إنشاء عناصر مع اسم مجال محدد.

يمكن لهذا الأسلوب إرجاع عنصر Element.

النحو:

createElementNS(ns,name)
مقام وصف
نامس قيمة نصية، يمكن استخدامها لتسمية اسم المجال هذا العنصر.
اسم فارغ از كلمات، كان يُمكن لهذا العنصر المحدد تسمية هذا العنصر.

Description

createElementNS() method with createElement() methodSimilar, but it creates Element nodes that have a specified namespace in addition to the specified name. This method is only used in XML documents that use namespaces.

Example

In all examples, we will use XML files books.xml, and JavaScript functions loadXMLDoc().

The following code snippet can add an element node with a specified namespace to each <book>:

mlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName('book');
var newel,newtext;
for (i=0;i<x.length;i++)
  {
  newel=xmlDoc.createElementNS('p','edition');
  newtext=xmlDoc.createTextNode('First');
  newel.appendChild(newtext);
  x[i].appendChild(newel);
  }

Document Object Reference Manual