473,382 Members | 1,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

substitution for ms xml dom object

Hello,

I have got some standard problems still realized with MS xml 4. The
following code runs on Windows machines with python and win32com installed.

Could you use pyxml or 4suite to make every of these problems work on any
machine?

The standard problems are:

- Selecting many nodes with xPath
- Select a single node with xPath
- Append a child (to selected single node)

Here's the working code:
import win32com.client

class myTest:
def __init__(self):
self.xmlString = """<?xml version="1.0"?>
<wanted>
<item id="1">Mister X</item>
<item id="2">Mister Y</item>
<item id="3">Mister Z</item>
</wanted>
"""

print "Our test data is:"
print self.xmlString

self.Dom =
win32com.client.dynamic.Dispatch('Msxml2.DOMDocume nt.4.0')
self.Dom.loadXML(self.xmlString)

def Problem_1(self):
"'First problem: Selecting many nodes with xPath'"

xPath = "//item"

nodes = self.Dom.selectNodes(xPath)

for node in nodes:
print node.getAttribute("id") + ": " + node.text
def Problem_2(self):
"'Second problem: Select a single node with xPath'"

xPath = "//item[@id='2']"

node = self.Dom.selectSingleNode(xPath)

print node.getAttribute("id") + ": " + node.text
def Problem_3(self):
"'Third problem: Append a child'"

xPath = "/wanted"
parentNode = self.Dom.selectSingleNode(xPath)

childNode = self.Dom.createElement("item")
childNode.setAttribute("id", "4" )
childNode.text = "Mister No"

parentNode.appendChild(childNode)
test = myTest()

print test.Problem_1.__doc__
test.Problem_1()

print
print test.Problem_2.__doc__
test.Problem_2()

print
print test.Problem_3.__doc__
test.Problem_3()

print "result of Problem_3:"
print test.Dom.xml
Thanks for discussion,

--
Marko Faldix
Jul 18 '05 #1
0 1060

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Paddy | last post by:
Hi, I got tripped up on the way eval works with respect to modules and so wrote a test. It seems that a function carries around knowledge of the globals() present when it was defined. (The...
1
by: kollareddy | last post by:
Hi all, I am new to xml/xsd world. I want to know the differences between complex type and element being abstract and if both can be declared so, in case of substitution goups.Also can xsi:type...
4
by: Don | last post by:
I think "macro substitution" is the correct term for what I want to do, but, to be sure, here is a description of what I'd like to know is possible: I want to be able to create a create an object...
1
by: Brian Newman | last post by:
I have a form with five rows of text boxes, displaying data. For certain reasons, I can't bind these directly to data records, so I'm using code to load the data into an object, then manually get...
18
by: james | last post by:
Hi, I am loading a CSV file ( Comma Seperated Value) into a Richtext box. I have a routine that splits the data up when it hits the "," and then copies the results into a listbox. The data also...
5
by: Murali | last post by:
In Python, dictionaries can have any hashable value as a string. In particular I can say d = {} d = "Right" d = "Wrong" d = "test" In order to print "test" using % substitution I can say
4
by: Ian | last post by:
Hi, Hopefully a simple question but my brain is hurting... I want to make a regex substitution, using search and replace patterns contained in variables. What I want to do is: $f =...
11
by: mailforpr | last post by:
Is this design well-formed? It contradicts the LSP and Design by contract anyhow. LSP tells us that "In class hierarchies, it should be possible to treat a specialized object as if it were a base...
3
by: Skip | last post by:
OK, I'm a novice in JS but have lots of coding experience. I am trying to accomplish something that would seem somewhat simple - BUT IT'S NOT. I have a basic window that calls another window...
2
by: =?Utf-8?B?UGV0ZXI=?= | last post by:
In our application consisting of several custom user controls we want one of these controls to be excluded from the page cache. For this I tried to use the substitution control for output cache...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.