Skip to content

Commit

Permalink
WstxValidationException: Unknown reason (at end element
Browse files Browse the repository at this point in the history
</nl:nillableIntElement>) when validating a document with nillable
elements fix #179
  • Loading branch information
ppalaga committed Jan 10, 2024
1 parent 125b423 commit 17e6b70
Show file tree
Hide file tree
Showing 2 changed files with 240 additions and 30 deletions.
58 changes: 49 additions & 9 deletions src/main/java/com/ctc/wstx/sw/BaseNsStreamWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public abstract class BaseNsStreamWriter
* (we are in repairing mode)
*/
final protected boolean mAutomaticNS;

final protected EmptyElementHandler mEmptyElementHandler;

/*
Expand Down Expand Up @@ -169,7 +169,7 @@ public void setPrefix(String prefix, String uri)
}

/* 25-Sep-2004, TSa: Let's check that "xml" and "xmlns" are not
* (re-)defined to any other value, nor that value they
* (re-)defined to any other value, nor that value they
* are bound to are bound to other prefixes.
*/
/* 01-Apr-2005, TSa: And let's not leave it optional: such
Expand All @@ -193,7 +193,7 @@ public void setPrefix(String prefix, String uri)
throwOutputError(ErrorConsts.ERR_NS_REDECL_XMLNS_URI, prefix);
}
}

/* 05-Feb-2005, TSa: Also, as per namespace specs; the 'empty'
* namespace URI can not be bound as a non-default namespace
* (ie. for any actual prefix)
Expand Down Expand Up @@ -334,9 +334,6 @@ protected void writeTypedAttribute(String prefix, String nsURI, String localName
if (!mStartElementOpen) {
throwOutputError(ErrorConsts.WERR_ATTR_NO_ELEM);
}
if (mCheckAttrs) { // still need to ensure no duplicate attrs?
mCurrElem.checkAttrWrite(nsURI, localName);
}
try {
if (mValidator == null) {
if (prefix == null || prefix.length() == 0) {
Expand All @@ -346,7 +343,7 @@ protected void writeTypedAttribute(String prefix, String nsURI, String localName
}
} else {
mWriter.writeTypedAttribute
(prefix, localName, nsURI, enc, mValidator, getCopyBuffer());
(prefix, localName, nsURI, enc, mCurrElem.wrap(mValidator), getCopyBuffer());
}
} catch (IOException ioe) {
throw new WstxIOException(ioe);
Expand Down Expand Up @@ -494,7 +491,7 @@ protected final void doWriteAttr(String localName, String nsURI, String prefix,
throws XMLStreamException
{
if (mCheckAttrs) { // still need to ensure no duplicate attrs?
mCurrElem.checkAttrWrite(nsURI, localName);
mCurrElem.checkAttrWrite(nsURI, localName, prefix, value);
}
if (mValidator != null) {
// No need to get it normalized... even if validator does normalize
Expand Down Expand Up @@ -537,7 +534,7 @@ protected final void doWriteAttr(String localName, String nsURI, String prefix,
throws XMLStreamException
{
if (mCheckAttrs) { // still need to ensure no duplicate attrs?
mCurrElem.checkAttrWrite(nsURI, localName);
mCurrElem.checkAttrWrite(nsURI, localName, prefix, new String(buf, start, len));
}
if (mValidator != null) {
// No need to get it normalized... even if validator does normalize
Expand Down Expand Up @@ -763,4 +760,47 @@ protected abstract void writeStartOrEmpty(String localName, String nsURI)

protected abstract void writeStartOrEmpty(String prefix, String localName, String nsURI)
throws XMLStreamException;

@Override
public int getAttributeCount()
{
return mCurrElem.getAttributeCount();
}

@Override
public String getAttributeLocalName(int index)
{
return mCurrElem.getAttributeLocalName(index);
}

@Override
public String getAttributeNamespace(int index)
{
return mCurrElem.getAttributeNamespace(index);
}

@Override
public String getAttributePrefix(int index)
{
return mCurrElem.getAttributePrefix(index);
}

@Override
public String getAttributeValue(int index)
{
return mCurrElem.getAttributeValue(index);
}

@Override
public String getAttributeValue(String nsURI, String localName)
{
return mCurrElem.getAttributeValue(nsURI, localName);
}

@Override
public int findAttributeIndex(String nsURI, String localName)
{
return mCurrElem.findAttributeIndex(nsURI, localName);
}

}
Loading

0 comments on commit 17e6b70

Please sign in to comment.