You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Di Li <di...@googlemail.com> on 2007/03/14 13:54:11 UTC

How to find the group information by SAX-Parsing

Hi all,

i am now writing my master thesis and have a question about SAX:

I am trying to find the group information (sequence, choice and all) by
SAX-Parsing of a xml instance, which has been defined in the XML Schema.

for example, this is the schema:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="persons">
        <xs:complexType>
            <xs:sequence maxOccurs="unbounded">
                <xs:element name="name" type="xs:string" />
                <xs:element name="birthday" type="xs:date" minOccurs="0"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>


and this is its instance:

<?xml version="1.0" encoding="UTF-8"?>
<persons>
    <name>Schulz</name>
    <birthday>1970-04-15</birthday>
    <name>Ferner</name>
    <name>Lee</name>
    <birthday>1981-08-15</birthday>
</persons>

i want to find out by sax-parsing, that Schulz and 1970-04-15 are the
attributes of the first person, the second person has the name Ferner, and
the last two elements are the attributes of the third person.

Is there a standard solution for this problem? Actually the validator of the
SAX Parser does have the same problem. By validating of a XML document
relating to his schema the sax-based validator must also find the group
information. How does it work?

I researched seveval literatures, but didn't find any solutions. They just
say, that the SAX Parser has also the possibility to validate a doument and
how i can start the validater and how can i handle the validating errors.
The internal functionality of the validater is unknown.

I don't want to validate the whole document, but just to find the group
information. So i want to know, if there has been already a solution for it?
If yes, can anyone tell me, how it works or give me some sources to
research?

Thanks in advance!

Best Regards!

Di

Re: How to find the group information by SAX-Parsing

Posted by ke...@us.ibm.com.
> if there have been already some standard solutions from SAX,

No off-the-shelf libraries that I know of at the SAX level, since it's
usually easy to hand-code.

There are also data binding tools, which focus on parsing XML into
application-specific data structures. Those do_generally produce structures
based on the schema, and thus would tend to reflect the kind of
partitioning expressed therein. This might or might not be closer to what
you're looking for.


______________________________________
"... Three things see no end: A loop with exit code done wrong,
A semaphore untested, And the change that comes along. ..."
  -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish
(http://www.ovff.org/pegasus/songs/threes-rev-11.html)

Re: How to find the group information by SAX-Parsing

Posted by Di Li <di...@googlemail.com>.
First of all thank you very much for your help!

Certainly the standard solution is to structure the data properly. But some
customers of the company (SAP), where i am writing my master thesis, didn't
do the standard thing. They are defining their data structures relying on
sequence of children to imply grouping. So one of my tasks is to solve this
problem, because we can't order the customera to change their existing
structures.

My idea to solve this problem is almost the same as yours. I will explain it
later. But i want to say here, that as a student, who is writing his master
thesis, i must try to find out and to research the existing solutions on the
market and then to evaluate them. So my question is, if there have been
already some standard solutions from SAX, or there are some existing
solutions from other people or companies.

Now i will explain my basic idea to solve the problem: I want to insert
several elements into the instance by parsing it, which group the children.

Something like this:

<?xml version="1.0" encoding="UTF-8"?>
<persons>
   <sequence>
      <name>Schulz</name>
      <birthday>1970-04-15</birthday>
  </sequence>
  <sequence>
      <name>Ferner</name>
  </sequence>
  <sequence>
      <name>Lee</name>
      <birthday>1981-08-15</birthday>
  </sequence>
</persons>

It doesn't mean that i really insert elements into the instance, but to
create several new sax events. The program logic will be then implemented in
the methods startElement() and endElement(). There is also a very important
point: The structure information about sequence, or choice, or all, which
was defined in the schema, must be forwarded to the sax parser.

Then it works. In my opinion we dont't need to accumulate data because of
UPA (unique particle attribution). So we can have then a good performance.
You can find further information about UPA under
http://www.edition-w3c.de/TR/2001/REC-xmlschema-1-20010502/.

I am waiting for your suggestion, and also from other members. Do you think
it is a good algorithm to find the group information out?

Thanx again!

Di

Re: How to find the group information by SAX-Parsing

Posted by ke...@us.ibm.com.
The standard solution is to structure the data properly, so you have a
<person> which contains all the information about a person, rather than
relying on sequence of children to imply grouping.

If you must rely on sequence, basically you're writing a simple FSM that
accumulates data, acting on that accumulated info and resetting  each time
it sees a new <name> (or when it runs out of children). Standard SAX
processing; you should be able to find lots of examples on the web.

______________________________________
"... Three things see no end: A loop with exit code done wrong,
A semaphore untested, And the change that comes along. ..."
  -- "Threes" Rev 1.1 - Duane Elms / Leslie Fish
(http://www.ovff.org/pegasus/songs/threes-rev-11.html)

Re: How to find the group information by SAX-Parsing

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
A couple related questions have been asked in the last few months on this 
list. You might find the following posts [1][2][3] useful.

[1] 
http://mail-archives.apache.org/mod_mbox/xerces-j-users/200611.mbox/%3cOF3FC5C732.E64ED602-ON85257230.001A96E6-85257230.001CB35F@ca.ibm.com%3e
[2] 
http://mail-archives.apache.org/mod_mbox/xerces-j-users/200701.mbox/%3cOF647B3E27.418AE072-ON8525726D.0066649C-8525726D.006838DD@ca.ibm.com%3e
[3] 
http://mail-archives.apache.org/mod_mbox/xerces-j-users/200701.mbox/%3cOFC6F1BBCD.17F9671A-ON8525726D.007880FE-8525726D.007BED36@ca.ibm.com%3e

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

"Di Li" <di...@googlemail.com> wrote on 03/14/2007 08:54:11 AM:

> Hi all,
> 
> i am now writing my master thesis and have a question about SAX:
> 
> I am trying to find the group information (sequence, choice and all)
> by SAX-Parsing of a xml instance, which has been defined in the XML 
Schema. 
> 
> for example, this is the schema:
> 
> <?xml version="1.0" encoding="utf-8"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema ">
>     <xs:element name="persons">
>         <xs:complexType>
>             <xs:sequence maxOccurs="unbounded">
>                 <xs:element name="name" type="xs:string" /> 
>                 <xs:element name="birthday" type="xs:date" 
minOccurs="0"/>
>             </xs:sequence>
>         </xs:complexType>
>     </xs:element>
> </xs:schema> 
> 
> 
> and this is its instance:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <persons>
>     <name>Schulz</name>
>     <birthday>1970-04-15</birthday>
>     <name>Ferner</name>
>     <name>Lee</name>
>     <birthday>1981-08-15</birthday>
> </persons>
> 
> i want to find out by sax-parsing, that Schulz and 1970-04-15 are 
> the attributes of the first person, the second person has the name 
> Ferner, and the last two elements are the attributes of the third 
person. 
> 
> Is there a standard solution for this problem? Actually the 
> validator of the SAX Parser does have the same problem. By 
> validating of a XML document relating to his schema the sax-based 
> validator must also find the group information. How does it work? 
> 
> I researched seveval literatures, but didn't find any solutions. 
> They just say, that the SAX Parser has also the possibility to 
> validate a doument and how i can start the validater and how can i 
> handle the validating errors. The internal functionality of the 
> validater is unknown. 
> 
> I don't want to validate the whole document, but just to find the 
> group information. So i want to know, if there has been already a 
> solution for it? If yes, can anyone tell me, how it works or give me
> some sources to research? 
> 
> Thanks in advance!
> 
> Best Regards!
> 
> Di 

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org