---
sourceDocument: Référence API Brésil
sourceDocumentLink: https://servicenow-prod.fluidtopics.net/r/fr-FR/api-reference

 Release :

    - brazil

ft:locale :

    - fr-FR

ft:publication_title :

    - Référence API Brésil

ft:clusterId :

    - crapiref

bundleId :

    - crapiref

workflow :

    - Creator


---

# XMLNode : délimité, global

# XMLNode : délimité, global {#ariaid-title1}

Rversion finale: Brazil  
Mis à jour 10 sept. 2026  
![](https://www.servicenow.com/docs/portal-asset/ico-clock) 4 minutes de lecture  
L'API XMLNode fournit des méthodes pour interroger des valeurs à partir de nœuds XML. Les XMLNodes sont extraits des objets XMLDocument2, qui contiennent des chaînes XML.

Il n'existe aucun constructeur permettant de créer une instance autonome d'un objet XMLNnode. Utilisez plutôt la méthode createElement() de [XMLDocument2](https://servicenow-prod.fluidtopics.net/Y196b6CKv2Ab5OnXnK_uRw#c_XMLDocument2ScopedAPI "L’API XMLDocument2 est une couche d’objet JavaScript permettant d’analyser et d’extraire des données XML à partir d’une chaîne XML."), qui ajoute un nœud à un document existant.

## Code XML dans le champ d'application : getAttribute(attribut de chaîne) {#ariaid-title2}

Obtient la valeur de l'attribut.
{#r_ScopedXMLNodeGetAttribute_String__table_ir2_12p_1r__entry__3}

| Nom | Type | Description |
|-|-|-|
| attribut | Chaîne | Nom de l'attribut. |
[Tableau 1. Paramètres]

{#r_ScopedXMLNodeGetAttribute_String__table_ir2_12p_1r} {#r_ScopedXMLNodeGetAttribute_String__table_kr2_12p_1r__entry__2}

| Type | Description |
|-|-|
| Chaîne | La valeur de l'attribut. |
[Tableau 2. Renvoie]

{#r_ScopedXMLNodeGetAttribute_String__table_kr2_12p_1r}  

    var xmlString = "<test>" +
                    "  <one>" +
                    "    <two att=\"xxx\">abcd1234</two>" +
                    "    <three boo=\"yah\" att=\"yyy\">1234abcd</three>" +
                    "    <two>another</two>" +
                    "  </one>" +
                    "  <number>1234</number>" +
                    "</test>";
    var xmlDoc = new XMLDocument2();
    xmlDoc.parseXML(xmlString);
    var node = xmlDoc.getNode('//two');
    gs.info(node.getAttribute('att'));

Sortie :

    xxx

## XMLNode dans le champ d'application : getAttributes() {#ariaid-title3}

Renvoie un objet contenant les attributs du nœud sous forme de propriétés avec valeurs.
{#r_SXMLN_getAttributes__table_bk3_rjy_3x__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucune |   |   |
[Tableau 3. Paramètres]

{#r_SXMLN_getAttributes__table_bk3_rjy_3x} {#r_SXMLN_getAttributes__table_ck3_rjy_3x__entry__2}

| Type | Description |
|-|-|
| Objet | Contient des paires nom-valeur où le nom est l'attribut et la valeur est la valeur de l'attribut. |
[Tableau 4. Renvoie]

{#r_SXMLN_getAttributes__table_ck3_rjy_3x}

## XMLNode dans le champ d'application : getChildNodeIterator() {#ariaid-title4}

Obtient un objet XMLNodeIterator qui peut être utilisé pour parcourir la liste des nœuds enfants.
{#r_ScopedXMLNodeGetChildNodeIterator__table_ng3_xfc_2r__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucune |   |   |
[Tableau 5. Paramètres]

{#r_ScopedXMLNodeGetChildNodeIterator__table_ng3_xfc_2r} {#r_ScopedXMLNodeGetChildNodeIterator__table_brm_x2p_1r__entry__2}

| Type | Description |
|-|-|
| XMLNodeIterator | L'objet de l'itérateur de nœud. |
[Tableau 6. Renvoie]

{#r_ScopedXMLNodeGetChildNodeIterator__table_brm_x2p_1r}  

    var xmlString = "<test>" +
                    "  <one>" +
                    "    <two att=\"xxx\">abcd1234</two>" +
                    "    <three boo=\"yah\" att=\"yyy\">1234abcd</three>" +
                    "    <two>another</two>" +
                    "  </one>" +
                    "  <number>1234</number>" +
                    "</test>";
    var xmlDoc = new XMLDocument2();
    xmlDoc.parseXML(xmlString);
    var node = xmlDoc.getNode('//one');
    var iter= node.getChildNodeIterator();
    gs.info(iter.hasNext());

## XMLNode dans le champ d'application : getFirstChild() {#ariaid-title5}

Obtient le premier nœud enfant du nœud.
{#r_ScopedXMLNodeGetFirstChild__table_wbb_wfc_2r__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucune |   |   |
[Tableau 7. Paramètres]

{#r_ScopedXMLNodeGetFirstChild__table_wbb_wfc_2r} {#r_ScopedXMLNodeGetFirstChild__table_ecg_ccp_1r__entry__2}

| Type | Description |
|-|-|
| Code XML | Le premier nœud enfant du nœud. |
[Tableau 8. Renvoie]

{#r_ScopedXMLNodeGetFirstChild__table_ecg_ccp_1r}  

    var xmlString = "<test>" +
                    "<one>" +
                    "<two att=\"xxx\">abcd1234</two>" +
                    "<three boo=\"yah\" att=\"yyy\">1234abcd</three>" +
                    "<two>another</two>" +
                    "</one>" +
                    "<number>1234</number>" +
                    "</test>";
    var xmlDoc = new XMLDocument2();
    xmlDoc.parseXML(xmlString);
    var node = xmlDoc.getNode('//one');
    gs.info(node.getFirstChild());

Sortie :

    <two att="xxx">abcd1234</two>

## XMLNode dans le champ d'application : getLastChild() {#ariaid-title6}

Obtient le dernier nœud enfant du nœud.
{#r_ScopedXMLNodeGetLastChild__table_gw2_vfc_2r__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucune |   |   |
[Tableau 9. Paramètres]

{#r_ScopedXMLNodeGetLastChild__table_gw2_vfc_2r} {#r_ScopedXMLNodeGetLastChild__table_kgc_pbp_1r__entry__2}

| Type | Description |
|-|-|
| Code XML | Le dernier enfant du nœud. |
[Tableau 10. Renvoie]

{#r_ScopedXMLNodeGetLastChild__table_kgc_pbp_1r}  

    var xmlString = "<test>" +
                    "<one>" +
                    "<two att=\"xxx\">abcd1234</two>" +
                    "<three boo=\"yah\" att=\"yyy\">1234abcd</three>" +
                    "<two>another</two>" +
                    "</one>" +
                    "<number>1234</number>" +
                    "</test>";
    var xmlDoc = new XMLDocument2();
    xmlDoc.parseXML(xmlString);
    var node = xmlDoc.getNode('//one');
     
    gs.info(node.getLastChild());

Sortie :

    <two>another</two>

## XMLNode dans le champ d'application : getNodeName() {#ariaid-title7}

Obtient le nom du nœud. Le nom d'un nœud est déterminé par le type de nœud. Le nom d'un nœud document-élément est #document. Le nom d'un nœud de texte est #text. Le nom d'un nœud d'élément est le nom de l'élément.
{#r_ScopedXMLNodeGetNodeName__table_oxk_vfc_2r__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucune |   |   |
[Tableau 11. Paramètres]

{#r_ScopedXMLNodeGetNodeName__table_oxk_vfc_2r} {#r_ScopedXMLNodeGetNodeName__table_ftf_1dp_1r__entry__2}

| Type | Description |
|-|-|
| Chaîne | Nom du nœud. |
[Tableau 12. Renvoie]

{#r_ScopedXMLNodeGetNodeName__table_ftf_1dp_1r}  

    var xmlString = "<test>" +
                    "  <one>" +
                    "    <two att=\"xxx\">abcd1234</two>" +
                    "    <three boo=\"yah\" att=\"yyy\">1234abcd</three>" +
                    "    <two>another</two>" +
                    "  </one>" +
                    "  <number>1234</number>" +
                    "</test>";
    var xmlDoc = new XMLDocument2();
    xmlDoc.parseXML(xmlString);
    var node = xmlDoc.getNode('//two');
    gs.info(node.getNodeName());

Sortie :

    two

## XMLNode dans le champ d'application : getNodeValue() {#ariaid-title8}

Obtient la valeur du nœud. La valeur d'un nœud est déterminée par le type de nœud. Les nœuds élément et document-élément renvoient null.
{#r_ScopedXMLNodeGetNodeValue__table_jbm_tfc_2r__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucune |   |   |
[Tableau 13. Paramètres]

{#r_ScopedXMLNodeGetNodeValue__table_jbm_tfc_2r} {#r_ScopedXMLNodeGetNodeValue__table_djn_4cp_1r__entry__2}

| Type | Description |
|-|-|
| Chaîne | La valeur du nœud. |
[Tableau 14. Renvoie]

{#r_ScopedXMLNodeGetNodeValue__table_djn_4cp_1r}  

    var xmlString = "<test>" +
                    "  <one>" +
                    "    <two att=\"xxx\">abcd1234</two>" +
                    "    <three boo=\"yah\" att=\"yyy\">1234abcd</three>" +
                    "    <two>another</two>" +
                    "  </one>" +
                    "  <number>1234</number>" +
                    "</test>";
    var xmlDoc = new XMLDocument2();
    xmlDoc.parseXML(xmlString);
    var node = xmlDoc.getNode('//two');
    gs.info(node.getNodeValue());

Sortie :

    null

## XMLNode dans le champ d'application : getTextContent() {#ariaid-title9}

Obtient le contenu du texte du nœud actuel. Le contenu textuel d'un nœud se compose de tous les nœuds de texte enfants du nœud
{#r_ScopedXMLNodeGetTextContent__table_g21_tfc_2r__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucune |   |   |
[Tableau 15. Paramètres]

{#r_ScopedXMLNodeGetTextContent__table_g21_tfc_2r} {#r_ScopedXMLNodeGetTextContent__table_igr_z1p_1r__entry__2}

| Type | Description |
|-|-|
| Chaîne | Contenu textuel du nœud actuel. |
[Tableau 16. Renvoie]

{#r_ScopedXMLNodeGetTextContent__table_igr_z1p_1r}  

    var xmlString = "<test>" +
                    "  <one>" +
                    "    <two att=\"xxx\">abcd1234</two>" +
                    "    <three boo=\"yah\" att=\"yyy\">1234abcd</three>" +
                    "    <two>another</two>" +
                    "  </one>" +
                    "  <number>1234</number>" +
                    "</test>";
    var xmldoc = new XMLDocument2();
    xmldoc.parseXML(xmlString);
    var node = xmldoc.getNode('//one/two');
    gs.info(node.getTextContent());

Sortie :

    abcd1234

## XML dans le champ d'application : hasAttribute(attribut de chaîne) {#ariaid-title10}

Détermine si le nœud possède l'attribut spécifié.
{#r_ScopedXMLNodeHasAttribute_String__table_art_mdp_1r__entry__3}

| Nom | Type | Description |
|-|-|-|
| attribut | Chaîne | Le nom de l'attribut à vérifier. |
[Tableau 17. Paramètres]

{#r_ScopedXMLNodeHasAttribute_String__table_art_mdp_1r} {#r_ScopedXMLNodeHasAttribute_String__table_crt_mdp_1r__entry__2}

| Type | Description |
|-|-|
| Booléen | Vrai si le nœud possède l'attribut. |
[Tableau 18. Renvoie]

{#r_ScopedXMLNodeHasAttribute_String__table_crt_mdp_1r}  

    var xmlString = "<test>" +
                    "  <one>" +
                    "    <two att=\"xxx\">abcd1234</two>" +
                    "    <three boo=\"yah\" att=\"yyy\">1234abcd</three>" +
                    "    <two>another</two>" +
                    "  </one>" +
                    "  <number>1234</number>" +
                    "</test>";
    var xmlDoc = new XMLDocument2();
    xmlDoc.parseXML(xmlString);
    var node = xmlDoc.getNode('//two');
    gs.info(node.hasAttribute('att'));

Sortie :

    true

## XMLNode inclus dans le champ d'application : isCDATANode() {#ariaid-title11}

Indique si le nœud CDATA est conservé en tant que nœud distinct.
Utilisez la méthode pour vous assurer que les [XMLDocument2 inclus dans le champ d'application : setEnableCDATAReporting(booléen, activer)](https://servicenow-prod.fluidtopics.net/Y196b6CKv2Ab5OnXnK_uRw#SXMLD_setEnableCDATAReporting_B "Définit si les nœuds sont traités comme CDATA ou comme du texte normal après analyse. La génération de rapports CDATA est désactivée par défaut.") nœuds CDATA sont préservés et ne sont pas traités comme du texte.
{#SXMLN_isCDATANode__table_bk3_rjy_3x__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucune |   |   |
[Tableau 19. Paramètres]

{#SXMLN_isCDATANode__table_bk3_rjy_3x} {#SXMLN_isCDATANode__table_ck3_rjy_3x__entry__2}

| Type | Description |
|-|-|
| Booléen | Marqueur indiquant si un nœud interrogé est de type CDATA ou du texte brut. Valeurs valides : * true : le nœud interrogé est CDATA. * faux : le nœud interrogé est en texte brut. {#SXMLN_isCDATANode__ul_fj4_svh_lzb} |
[Tableau 20. Renvoie]

{#SXMLN_isCDATANode__table_ck3_rjy_3x}  
L'exemple suivant montre comment analyser une chaîne XML avec la génération de rapports CDATA activée à l'aide [XMLDocument2 inclus dans le champ d'application : setEnableCDATAReporting(booléen, activer)](https://servicenow-prod.fluidtopics.net/Y196b6CKv2Ab5OnXnK_uRw#SXMLD_setEnableCDATAReporting_B "Définit si les nœuds sont traités comme CDATA ou comme du texte normal après analyse. La génération de rapports CDATA est désactivée par défaut.") de . Le code utilise isCDATANode() pour montrer que le premier nœud interrogé dans la chaîne XML est un nœud CDATA.

    var xmlString = "<test>" +
      "  <one>" +
      "    <two att=\"xxx\">abcd1234</two>" +
      "    <three boo=\"yah\" att=\"yyy\">1234abcd</three>"+
      "    <four><![CDATA[another]]>element</four>" +
      "  </one>" +
      "  <number>1234</number>" +
      "</test>";
    var xmlDoc = new XMLDocument2();
    xmlDoc.setEnableCDATAReporting(true); // Enables CDATA reporting
    xmlDoc.parseXML(xmlString);
    var content = xmlDoc.getFirstNode('/test/one/four');
    gs.info(content.getFirstChild().isCDATANode());

Sortie :

    true

## XMLNode dans le champ d'application : toString() {#ariaid-title12}

Renvoie la valeur de chaîne du nœud actuel.
{#r_ScopedXMLNodeToString__table_jjy_pfc_2r__entry__3}

| Nom | Type | Description |
|-|-|-|
| Aucune |   |   |
[Tableau 21. Paramètres]

{#r_ScopedXMLNodeToString__table_jjy_pfc_2r} {#r_ScopedXMLNodeToString__table_bqm_nfp_1r__entry__2}

| Type | Description |
|-|-|
| Chaîne | Valeur de chaîne du nœud actuel. |
[Tableau 22. Renvoie]

{#r_ScopedXMLNodeToString__table_bqm_nfp_1r}  

    var xmlString = "<test>" +
                    "  <one>" +
                    "    <two att=\"xxx\">abcd1234</two>" +
                    "    <three boo=\"yah\" att=\"yyy\">1234abcd</three>" +
                    "    <two>another</two>" +
                    "  </one>" +
                    "  <number>1234</number>" +
                    "</test>";
    var xmlDoc = new XMLDocument2();
    xmlDoc.parseXML(xmlString);
    var node = xmlDoc.getNode('//one');
    gs.info(node.toString());

Sortie : Des sauts de ligne ont été ajoutés à la sortie.

    <one>    
    <two att="xxx">abcd1234</two>    
    <three att="yyy" boo="yah">1234abcd</three>    
    <two>another</two>  
    </one>


