[ 
https://issues.apache.org/jira/browse/XERCESC-2060?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Nuckols updated XERCESC-2060:
----------------------------------
    Description: 
Issue 1187 not completely resolved.
The following modification to that issue shows that when xsi:nil="true" is 
encountered within an <any> section in a top level element, the parser 
complains that the entire node should be empty.

schema:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns="http://www.w3schools.com";
elementFormDefault="qualified"
targetNamespace="http://www.w3schools.com";>
    <xs:element name="note">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="to" type="xs:string"/>
                <xs:element name="from" type="xs:string"/>
                <xs:any namespace="##any" processContents="skip" 
maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

example:
<?xml version="1.0"?>
<note xmlns="http://www.w3schools.com";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://www.w3schools.com note.xsd">
    <to>Tove</to>
    <from>Jani</from>
    <school>
        <student xsi:nil="true"/>
    </school>
    <random xsi:nil="true"></random>
</note>

result from schema validation:
../StdInParse -n -s < test.xml

Error at (file stdin, line 11, char 8): element 'note' is nil and must be empty


I debugged the issue within the IGXMLScanner code and know the root cause:
Internally, as attributes are scanned per element in the scanner method:
scanRawAttrListforNameSpaces()  the validator object is modified when any 
xsi:nil="true" is encountered.  This is normally fine when the actual element 
will be validated (i.e. fValidate == true) because the checkContent() method of 
the validator is called during the scanEndTag() method, resetting the state of 
fNil/fNilFound.

When fValidate == false (i.e. within a <any> tag with processContents="skip"),  
scanRawAttrListforNameSpaces continues to modify the fNil/fNilFound variables 
within the validator on an element by element case.  Therefore if the last 
element in the <any> block has xsi:nil="true" when the final scanEndTag() for 
the parent element is called the state of the fNil/fNilFound variables in the 
validator are left incorrect.

I think the solution might be to store the fNil/fNilFound states within the 
element stack so that as scanEndTag calls fire off, the correct state is 
maintained.



  was:
Issue 1187 not completely resolved.
The following modification to that issue shows that when xsi:nil="true" is 
encountered within an <any> section in a top level element, the parser 
complains that the entire node should be empty.

schema:
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
xmlns="http://www.w3schools.com";
elementFormDefault="qualified"
targetNamespace="http://www.w3schools.com";>
    <xs:element name="note">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="to" type="xs:string"/>
                <xs:element name="from" type="xs:string"/>
                <xs:any namespace="##any" processContents="skip" 
maxOccurs="unbounded"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

example:
<?xml version="1.0"?>
<note xmlns="http://www.w3schools.com";
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
xsi:schemaLocation="http://www.w3schools.com note.xsd">
    <to>Tove</to>
    <from>Jani</from>
    <school>
        <student xsi:nil="true"/>
    </school>
    <random xsi:nil="true"></random>
</note>

result from schema validation:
../StdInParse -n -s < test.xml

Error at (file stdin, line 11, char 8): element 'note' is nil and must be empty


I debugged the issue within the IGXMLScanner code and know the root cause:
Internally, as attributes are scanned per element in the scanner method:
scanRawAttrListforNameSpaces()  the validator object is modified when any 
xsi:nil="true" is encountered.  This is normally fine when the actual element 
will be validated (i.e. fValidate == true) because the checkContent() method of 
the validator is called during the scanEndTag() method, resetting the state of 
fNil/fNilFound

When fValidate == false (i.e. within a <any> tag with processContents="skip"),  
scanRawAttrListforNameSpaces continues to modify the fNil/fNilFound variables 
within the validator on an element by element case.  Therefore if the last 
element in the <any> block has xsi:nil="true" when the final scanEndTag() for 
the parent element is called the state of the fNil/fNilFound variables in the 
validator are left incorrect.

I think the solution might be to store the fNil/fNilFound states within the 
element stack so that as scanEndTag calls fire off, the correct state is 
maintained.




> Reopening of Issue XERCESC-1187 Xerces SAX2 parser can not skip xs:any if 
> xsi:nil is used in xml
> ------------------------------------------------------------------------------------------------
>
>                 Key: XERCESC-2060
>                 URL: https://issues.apache.org/jira/browse/XERCESC-2060
>             Project: Xerces-C++
>          Issue Type: Bug
>          Components: Validating Parser (XML Schema)
>    Affects Versions: 3.1.2
>         Environment: Linux Intel 64 Bit 
>            Reporter: Eric Nuckols
>
> Issue 1187 not completely resolved.
> The following modification to that issue shows that when xsi:nil="true" is 
> encountered within an <any> section in a top level element, the parser 
> complains that the entire node should be empty.
> schema:
> <?xml version="1.0"?>
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
> xmlns="http://www.w3schools.com";
> elementFormDefault="qualified"
> targetNamespace="http://www.w3schools.com";>
>     <xs:element name="note">
>         <xs:complexType>
>             <xs:sequence>
>                 <xs:element name="to" type="xs:string"/>
>                 <xs:element name="from" type="xs:string"/>
>                 <xs:any namespace="##any" processContents="skip" 
> maxOccurs="unbounded"/>
>             </xs:sequence>
>         </xs:complexType>
>     </xs:element>
> </xs:schema>
> example:
> <?xml version="1.0"?>
> <note xmlns="http://www.w3schools.com";
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xsi:schemaLocation="http://www.w3schools.com note.xsd">
>     <to>Tove</to>
>     <from>Jani</from>
>     <school>
>         <student xsi:nil="true"/>
>     </school>
>     <random xsi:nil="true"></random>
> </note>
> result from schema validation:
> ../StdInParse -n -s < test.xml
> Error at (file stdin, line 11, char 8): element 'note' is nil and must be 
> empty
> I debugged the issue within the IGXMLScanner code and know the root cause:
> Internally, as attributes are scanned per element in the scanner method:
> scanRawAttrListforNameSpaces()  the validator object is modified when any 
> xsi:nil="true" is encountered.  This is normally fine when the actual element 
> will be validated (i.e. fValidate == true) because the checkContent() method 
> of the validator is called during the scanEndTag() method, resetting the 
> state of fNil/fNilFound.
> When fValidate == false (i.e. within a <any> tag with 
> processContents="skip"),  scanRawAttrListforNameSpaces continues to modify 
> the fNil/fNilFound variables within the validator on an element by element 
> case.  Therefore if the last element in the <any> block has xsi:nil="true" 
> when the final scanEndTag() for the parent element is called the state of the 
> fNil/fNilFound variables in the validator are left incorrect.
> I think the solution might be to store the fNil/fNilFound states within the 
> element stack so that as scanEndTag calls fire off, the correct state is 
> maintained.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscr...@xerces.apache.org
For additional commands, e-mail: c-dev-h...@xerces.apache.org

Reply via email to