Skip to main content

Parsing XML document

1 reply [Last post]
Joined: 2005-05-31

I have such a problem:
I have XML document that uses XSD-schema.
In XSD-schema there is element that have two atributes:

And in XML document I write:

According to the XSD-schema parser must add to El1 second attribute "atr2" with its default value because it has default value. But when I do such a code:

factory = DocumentBuilderFactory.newInstance();
builder = factory.newDocumentBuilder();
doc = builder.parse(new File("file1.xml"));
Element pEl;
pEl = doc.getDocumentElement()
NamedNodeMap Attribs = pEl.getAttributes();

In the list of attributes "Attribs" - there is no attribute "attr1"!!!

What I have to do???

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-20


This is not the correct forum for such topics. This forum is about the relationship between binary Web service protocols and XML Web service protocols. Try using this forum instead:

However, i will answer just this once :-)

You need to tell JAXP to validate you document, JAXP also needs to know how to get access to the XSD. Read up on the JAXP API for more info or ask on the above forum.

There are also some problems with your XSD and XML:

1) you are also using the 'xsd' prefix for one attribute.

2) The character '|' is illegal and not allowed in element names for XML 1.0 or XML 1.1 documents. You are only allowed the following punctuations for the second and following characters: '.', '-', '_', ':'. See here [1] for the allowed set of charactes. I am surprised your XML parsed.