Thursday, October 11, 2012 9:39 AM
In my XML File I have the following XML attribute:
I also use a XSD file to validate the XML with DOM. The validation succeeded. "myIntAttribute"="4711"
is in the XSD specified as decimal (I also tried the following tests with xsd:integer). Here is how I
specified it's type in the XSD:
<xsd:attribute name=""myIntAttribute"="4711"" type="xsd:decimal"/>
Since validation succeeded and their is a pure digit value ("4711") assigned to "myIntAttribute"
it must be an integer attribute in the DOM tree.
Herewith I tried to retrieve it's value:
VARIANT v_myIntAttribute = spElement -> getAttribute( "myIntAttribute" );
int i_myIntAttribute = v_myIntAttribute.intVal;
i_myIntAttribute = v_myIntAttribute.iVal;
Neither .intVal nor .iVal did retrieve the correct value.
1. What is the reason for the problem and how can it be fixed?
2. What is the best way in DOM-API to retrieve the integer value of an integer attribute?
Monday, October 15, 2012 2:36 AM
In the DOM, attributes are nodes. Unlike element nodes, attribute nodes have text values.
The way to get the value of an attribute, is to get its text value.
You need to convert the type manually.
Go go Doraemon!
- Marked As Answer by ThePerfectWave Tuesday, October 16, 2012 8:16 AM
Monday, October 15, 2012 8:47 AMThanks for your answer.
That's what I currently do: "I retrieve the text value and convert it"
But I thought, since DOM is a big API with a lot of functions and
I already declared that attribute in XSD as integer,
that therefore it should be possible to have a direct way to
retrieve attributes as integer. ==> It seems to me a little bit
strange - that this is not the case.
You said ".... unlike element nodes..."
==> Is it possible to retrieve "integer element nodes" directly as integers?
Tuesday, October 16, 2012 2:00 AMModerator
Welcome to MSDN Forum.
I think this link can help you.
In the DOM, everything is a node. Element nodes do not have a text value. The text of an element node is stored in a child node. This node is called a text node. But attribute nodes unlike element nodes, they have text values.
Allen Li [MSFT]
MSDN Community Support | Feedback to us