[XML-SIG] xml-schema parsing using minidom.

Mariappan, MaharajanX m_mariappanX@trillium.com
Mon, 3 Dec 2001 22:43:28 -0800


Hi Martin

1) 
I'm getting the same error when I've modified 2 lines in PullDOM class
constructor.

When I tried Thomas's approach[Declare Namespace for xml], parsing is 
going through fine.

2) There is another question on created list from return value of
getAttribute() method.

See below function, which will collect all the enumeration values defined
within specified simpleType element and return that result list.

def getSimpleTypeValues(dom,simpletypeName):
	enums = []
	simpletypes = dom.getElementsByTagName("xsd:simpleType")
	for simpletype in simpletypes:
		#print "%s" % simpletype.getAttribute("name")
		if simpletype.getAttribute("name") == simpletypeName:
			enumerations =
simpletype.getElementsByTagName("xsd:enumeration")
			for enum in enumerations:
				enums.append(enum.getAttribute("value"))
	return enums

When I print using print "%s" % enums, It is printing like
[u'enum1', u'enum2']

Any reason for that why print with u' ' aling with list elements?


-----Original Message-----
From: Martin v. Loewis [mailto:martin@v.loewis.de]
Sent: Monday, December 03, 2001 1:19 PM
To: m_mariappanX@trillium.com
Cc: m_mariappanX@trillium.com; m_mariappanX@trillium.com;
xml-sig@python.org
Subject: Re: [XML-SIG] xml-schema parsing using minidom.


> But contents is different to version 1.6.
> 
> class PullDOM(xml.sax.ContentHandler):
>     def __init__(self):
>         self.firstEvent = [None, None]
>         self.lastEvent = self.firstEvent
>         self._ns_contexts = [{}] # contains uri -> prefix dicts
>         self._current_context = self._ns_contexts[-1]

It should then read

class PullDOM(xml.sax.ContentHandler):
    def __init__(self):
        from xml.dom import XML_NAMESPACE
        self.firstEvent = [None, None]
        self.lastEvent = self.firstEvent
        self._ns_contexts = [{XML_NAMESPACE:'xml'}] # contains uri -> prefix
dicts
        self._current_context = self._ns_contexts[-1]


> 2) My aim of using PyExpat is not only parsing the schema file but
> also to print the variants enum value.
> 
> It is not giving any parse error. But the function
"getAvailableVariants()"
> is not working as we expect to print enums. 
> 
> It is not even printing available simpleTypes.

Since you are parsing in a namespace-aware mode, you also need to use
the namespace API. So replace

	simpletypes = dom.getElementsByTagName("xsd:simpleType")

with

	simpletypes = dom.getElementsByTagNameNS(XSD,"simpleType")


where

XSD="http://www.w3.org/2001/XMLSchema"

HTH,
Martin