Skip to Content.
Sympa Menu

xom-interest - [XOM-interest] Search and replace

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Arjan Huijzer <huijzer AT gmail.com>
  • To: XOM-interest AT lists.ibiblio.org
  • Cc:
  • Subject: [XOM-interest] Search and replace
  • Date: Tue, 19 Apr 2005 10:34:20 +0200

Hello,

I need to find a list of specific elements in my XML document, process them
and replace them with a new element.
The specific elements can be located throughout the doucment and I do not
know the easiest way to find them.

My code so far is:

File input = new File("chapter.xml");

Builder parser = new Builder();
Document doc = parser.build(input);


// Find all <illustrationrequest> elements in the XML document
Elements illReqElements = .........

for (int i = 0; i < illReqElements.size(); i++) {
Element illReqElement = illReqElements.get(i);
System.out.println(illReqElement.toXML());
}

I know that in the DOM specs there is a method getElementsByTagName(). Does
XOM contain a similar method? Or do I have to walk through the document
myself, recursively calling methods such as getChildElements()?

Thanks in advance for any help.

Arjan Huijzer




Archive powered by MHonArc 2.6.24.

Top of Page