Java: Utilisation de la classe ‘DocumentFragment’*

Author:

Java: Utilisation de la classe 'DocumentFragment'*
{filelink=8406}

/***** Code de MesExemples.com *******/
     //A Document Containing a Single Person Node/*]>            Frank Fangston        555-3247    */    public void addFragment(Document doc) {        Element person;        Element root = doc.getDocumentElement();        DocumentFragment fragment = doc.createDocumentFragment();        person = makePersonNode(doc,"Fred","555-4927");        fragment.appendChild(person);        person = makePersonNode(doc,"Sam","555-9832");        fragment.appendChild(person);        root.appendChild(fragment);    }    private Element makePersonNode(Document doc,String name,String phone) {        Element nameNode = doc.createElement("name");        Text nametextNode = doc.createTextNode(name);        nameNode.appendChild(nametextNode);        Element phoneNode = doc.createElement("phone");        Text phonetextNode = doc.createTextNode(phone);        phoneNode.appendChild(phonetextNode);                Element personNode = doc.createElement("person");        personNode.appendChild(nameNode);        personNode.appendChild(phoneNode);        return(personNode);    }                                      

Code testé avec le fichier XML Suivant




	Sakoba
	Adams
	Rappel
	Ne m'oubliez pas ce week-end!

A Voir sur le même Sujet:

  • Afficher Une Heure dans ma jframe avec timezone()

Leave a Reply

Your email address will not be published. Required fields are marked *

Java: Utilisation de la classe ‘DocumentFragment’*

Author:

Java: Utilisation de la classe 'DocumentFragment'*
{filelink=8406}

/***** Code de MesExemples.com *******/
     //A Document Containing a Single Person Node/*]>            Frank Fangston        555-3247    */    public void addFragment(Document doc) {        Element person;        Element root = doc.getDocumentElement();        DocumentFragment fragment = doc.createDocumentFragment();        person = makePersonNode(doc,"Fred","555-4927");        fragment.appendChild(person);        person = makePersonNode(doc,"Sam","555-9832");        fragment.appendChild(person);        root.appendChild(fragment);    }    private Element makePersonNode(Document doc,String name,String phone) {        Element nameNode = doc.createElement("name");        Text nametextNode = doc.createTextNode(name);        nameNode.appendChild(nametextNode);        Element phoneNode = doc.createElement("phone");        Text phonetextNode = doc.createTextNode(phone);        phoneNode.appendChild(phonetextNode);                Element personNode = doc.createElement("person");        personNode.appendChild(nameNode);        personNode.appendChild(phoneNode);        return(personNode);    }                                      

Code testé avec le fichier XML Suivant




	Sakoba
	Adams
	Rappel
	Ne m'oubliez pas ce week-end!

Leave a Reply

Your email address will not be published. Required fields are marked *