check schema for fixed attribute
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 26
- Joined: Mon Mar 04, 2013 1:42 pm
check schema for fixed attribute
Hi,
I have attributes defined in a xsd schema declared as "fixed" on some elements like this :
<xs:element name="ABC">
<xs:complexType>
<xs:sequence>
<xs:element ref="Lib"/>
<xs:element ref="Content"/>
</xs:sequence>
<xs:attribute name="special" type="xs:boolean" fixed="true"/>
</xs:complexType>
</xs:element>
The xml instances do not carry the attribute :
<ABC>
<Lib>This is Lib</Lib>
<Content>This is Content</Content>
</ABC>
Is there a way to check with java if an element has a fixed attribute declared in the schema ?
Regards,
Lionel
I have attributes defined in a xsd schema declared as "fixed" on some elements like this :
<xs:element name="ABC">
<xs:complexType>
<xs:sequence>
<xs:element ref="Lib"/>
<xs:element ref="Content"/>
</xs:sequence>
<xs:attribute name="special" type="xs:boolean" fixed="true"/>
</xs:complexType>
</xs:element>
The xml instances do not carry the attribute :
<ABC>
<Lib>This is Lib</Lib>
<Content>This is Content</Content>
</ABC>
Is there a way to check with java if an element has a fixed attribute declared in the schema ?
Regards,
Lionel
-
- Posts: 280
- Joined: Thu Nov 28, 2013 9:32 am
- Location: Hamburg/Germany
- Contact:
Re: check schema for fixed attribute
Hi Lionel,
you could load the file schema-aware. This way all the default and fixed attributes are expanded. But you won't be able to identify if an attribute was already set in the xml or has been added as default attribute.
Here's my (simplified) code to do this:
Regards,
Patrik
you could load the file schema-aware. This way all the default and fixed attributes are expanded. But you won't be able to identify if an attribute was already set in the xml or has been added as default attribute.
Here's my (simplified) code to do this:
Code: Select all
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import ro.sync.xml.parser.ParserCreator;
[...]
public static Document loadXmlFileSchemaAware(URL url) {
try {
final DocumentBuilder builder = ParserCreator.newSchemaAwareDocumentBuilder();
final Document document = builder.parse(url.getPath());
return document;
} catch(Exception e) {
return null;
}
}
Patrik
-
- Posts: 9421
- Joined: Fri Jul 09, 2004 5:18 pm
Re: check schema for fixed attribute
Hi,
Or if you have created a SAX parser to parse the XML documents, just set on it the property:
Regards,
Radu
Or if you have created a SAX parser to parse the XML documents, just set on it the property:
Code: Select all
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 26
- Joined: Mon Mar 04, 2013 1:42 pm
Re: check schema for fixed attribute
Hi,
The point is the file is open in an Author view and it is schema aware.
I can see the fixed attribute in grey in the attributes panel of the Author view but when I try to access it with to following code I get a null value.
If I try to parse the schema, I just parse one file, my schema include some sub-schemas (<xs:include schemaLocation="sub-schemas.xsd"/>) but the whole schema is already constructed inside oXygen as I can see in the attributes or elements panels and I can validate and make a lot of stuff in accordance with it, how can I check it ?
Regards,
Lionel
The point is the file is open in an Author view and it is schema aware.
I can see the fixed attribute in grey in the attributes panel of the Author view but when I try to access it with to following code I get a null value.
Code: Select all
if (fullySelectedNode.getType() == AuthorNode.NODE_TYPE_ELEMENT) {
AuthorElement element = (AuthorElement) fullySelectedNode;
AttrValue attrValue = element.getAttribute("special");
}
Regards,
Lionel
-
- Posts: 9421
- Joined: Fri Jul 09, 2004 5:18 pm
Re: check schema for fixed attribute
Hi Lionel,
Could you double check? I tested a similar situation and it works for me.
I'm assuming that the XML document opened in the Author editing mode properly refers to the XML Schema using the usual xsi:schemaLocation attribute. Otherwise, Oxygen does not know what schema is associated to the XML document.
Regards,
Radu
Could you double check? I tested a similar situation and it works for me.
I'm assuming that the XML document opened in the Author editing mode properly refers to the XML Schema using the usual xsi:schemaLocation attribute. Otherwise, Oxygen does not know what schema is associated to the XML document.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 26
- Joined: Mon Mar 04, 2013 1:42 pm
Re: check schema for fixed attribute
Hi Radu,
Yes it works if I add a xsi:schemaLocation attribute in my xml file.
I do not understand how oXygen knows about the xml schema I declare in my framework in all panels and validation and so on and not in my java code.
Best regards,
Lionel
Yes it works if I add a xsi:schemaLocation attribute in my xml file.
I do not understand how oXygen knows about the xml schema I declare in my framework in all panels and validation and so on and not in my java code.
Best regards,
Lionel
-
- Posts: 9421
- Joined: Fri Jul 09, 2004 5:18 pm
Re: check schema for fixed attribute
Hi Lionel,
Right now, when parsing the XML document to obtain the AuthorElement nodes structure Oxygen needs the XML to have a direct reference to the schema. We'll try to see if we can remove this limitation in a future version.
Regards,
Radu
Right now, when parsing the XML document to obtain the AuthorElement nodes structure Oxygen needs the XML to have a direct reference to the schema. We'll try to see if we can remove this limitation in a future version.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 9421
- Joined: Fri Jul 09, 2004 5:18 pm
Re: check schema for fixed attribute
Hi,
I forgot to ask if this is a showstopper for you. Oxygen uses the Xerces parser to parse the XML content and obtain the default attributes for each element while the content is parsed. And the Xerces parser loads and uses the XML Schema which is directly referenced by the XML document. So we would somehow need to redirect the parser to use an external schema while parsing, not impossible but also not very easy to do.
Regards,
Radu
I forgot to ask if this is a showstopper for you. Oxygen uses the Xerces parser to parse the XML content and obtain the default attributes for each element while the content is parsed. And the Xerces parser loads and uses the XML Schema which is directly referenced by the XML document. So we would somehow need to redirect the parser to use an external schema while parsing, not impossible but also not very easy to do.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service