RE: Parsed XML an ZCatalog
[email protected] Mon, 20 Oct 2003 12:48:34 -0700
| Newsgroups | gmane.comp.web.zope.parsed-xml |
|---|---|
| Message-ID | <AA7A72A46469D411B8B300508BE329500AE4DE79@desi2> |
Are you returning the element node or a text rendering (value) of the
element's child(ren)? You likely want a recursive utility script that
returns plain-text dump of element contents (including child elements -
useful for XHTML, for example) - here's some example code from a
Python-product I've written - it wouldn't be too hard to adapt this same
concept to a python script:
def _fragmentAsPlainText(self,elementNode=None):
"""
Renders a DOM node's children (representing XML fragment)
semi-recursively, as plain text, transforming paragraph tags
into line breaks.
"""
textval = ''
for childNode in elementNode.childNodes:
if childNode.nodeType == 3:
textval = textval + childNode.nodeValue
else:
if childNode.nodeType == 1:
if childNode.tagName != 'p':
textval = textval + \
self._fragmentAsPlainText(childNode)
else:
textval = textval + \
self._fragmentAsPlainText(childNode) + '\n'
return textval
Once you have done this, use a FieldIndex for "literal"/exact values, and a
ZCTextIndex or text-index for anything you want to do full-text searches on.
It might also be a good idea to set your Python's default encoding to utf-8
to deal with unicode issues in the XML documents you are using:
http://www.zug.cz/Members/Alekibango/Howtos/HowTo.i18n/document_view
> -----Original Message-----
> From: Jaared Scott [mailto:[email protected]]
> Sent: Monday, October 20, 2003 12:38 PM
> To: [email protected]
> Subject: RE: [Parsed-XML-Dev] Parsed XML an ZCatalog
>
>
> Sean,
>
> I have a py script that returns the the element that I am
> after..... I
> added an index that has the same name of the py script. I
> re-catalogued
> and it gives me... [] instead of the value. This is at least
> progress.
> Is there a specific type of index to use (keyword, field, etc)?
>
> Thanks!
>
> ===============================================
>
> Jaared Scott
> Systems Analyst
> Oklahoma Department of Career and Technology Education
> 405 743 5176
> [email protected]
>
> >>> <[email protected]> 10/20/03 11:59AM >>>
> You need to write schema-specific methods to get access to your data.
> If
> you want to index something like this: <headline>Foo</headline> you
> need to
> create a getHeadline method that can be called on the ParsedXML
> object.
>
> Write DOM traversal "accessor" methods (python scripts) in the root
> folder
> of your application (or CMF skins folder) for each field you care
> about
> extracting in the documents. Then add indexes to the catalog
> associated
> with those method names. You will then be able to index the results
> of
> document searches on a per-field basis. This only works in the case
> where
> you want your search result to point to the whole document, but you
> want to
> be able to specify fields on the document.
>
> > -----Original Message-----
> > From: Jaared Scott [mailto:[email protected]]
> > Sent: Thursday, October 16, 2003 1:05 PM
> > To: [email protected]
> > Subject: [Parsed-XML-Dev] Parsed XML an ZCatalog
> >
> >
> > I'm trying to perform searches on a parsed XML file. No luck yet.
> > Users come to my portal.... fill out a form and submit the form. My
> > form posts to a python script which creates an xml file (basically a
> > user profile). I would like to be able to search these xml
> > "user-profile" files. I created a Catalog and did the
> "find-objects"
> > thing by selecting "parsed XML." I'm not sure how to utilize the
> > indexes and meta-type features. I have tried both. The catalog
> finds
> > the xml objects..... but I can't seem to query elements within the
> xml
> > file. Heck, it might be better to do this in python...... I thought
> I
> > would try the catalog feature... so far I am getting nowhere... Any
> > gurus out there?
> >
> > Tux rules!
> >
> > ===============================================
> >
> > Jaared Scott
> > Systems Analyst
> > Oklahoma Department of Career and Technology Education
> > 405 743 5176
> > [email protected]
> >
> > _______________________________________________
> > Parsed-XML-Dev mailing list
> > [email protected]
> > http://mail.python.org/mailman/listinfo/parsed-xml-dev
> >
>