Xmldocnew activexobjectmicrosoft xmldom




















So, you have to print the root node using the printRootNode function, and from there on the printNode function takes over. Most scripts that interact with an entire XML document tree start at the root node and work their way down the tree, as shown in this example.

The rest of the code inside the script tag is inside the printNode function, and is executed when the printNode function is called by printRootNode. As you know, a document node provides all of the methods of the Node interface as well as those specific to the document interface. The printNode function will work with any node, including a document node; it is called and passed the xmlDoc variable as its argument to print the root node.

You may be wondering exactly how the printNode can print an entire document tree when it is only called and passed the root node. The answer has to do with a common programming technique called recursion. Recursion is to tree-like data structures what loops are to list data structures. When you want to process a number of similar things that are in a list, you simply process them one at a time until you've processed all of the items in that list.

Recursion is a bit more complex. When you're dealing with tree-like data structures, you have to work your way down each branch in the tree until you reach the end. Let's look at an example not associated with the DOM first. When you want to find a file on your computer's hard drive manually, and you have no idea where it is located, the fastest way to find it is to recursively search all of the directories on the hard drive.

The process goes something like this starting at the root directory :. That's one recursive algorithm. The most important thing to understand about recursion is that all of the items being processed recursively must be similar enough to be processed in the same way. This helps to explain why all of the interfaces in the DOM are extensions of the basic Node interface. You can write one recursive function that will process all of the nodes in a DOM tree using the methods that they have in common.

First, let's examine the function declaration. You've already seen a few functions, but let's back up and clarify how functions work in JavaScript. In JavaScript, you indicate that you're creating a function by using the function keyword.

The name of the function is supplied next, followed by the list of arguments accepted by the function. The name of this function is printNode , and it accepts one argument, which is given the name node. This argument is intended to be a node that's part of a DOM tree.

Within the function, you can use the name argument to refer to the node that is passed into the function. In the body of the function, the first thing that happens is the nodeName property of the node currently being processed is printed lines 26 and If a node value exists, it is printed next lines 28 and Skip to main content.

This browser is no longer supported. Download Microsoft Edge More info. Contents Exit focus mode. In this article. Adds a new schema to the schema collection and associates the given namespace URI with the specified schema.

Adds schemas from another collection into the current collection and replaces any schemas that collide on the same namespace URI. Add a comment. Active Oldest Votes. Improve this answer. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually.

Linked



0コメント

  • 1000 / 1000