You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by Mirko Braun <tb...@Softing.com> on 2003/12/11 10:49:29 UTC

problem with getElementById()

 Hi to all,

 i,m using the Xerces 2.3.0 to parse an XML-Document validating against a
Schema.
 When using the method getElementById() to get a node referenced by an IDREF
(see code below)
 a NULL-Pointer is given back. I'm sure that the ID is unique within the XML
Document.

 Is their any special feature i have to set according to the use of Schema
and Xerces?

 Can anybody help me? Thanks in advance.

 Mirko





C++ code:

	xercesc::DOMNode* pToDOMNode = oRevision.GetDOMNode();

	xercesc::DOMNamedNodeMap* pToAttr = pToDOMNode->getAttributes();

	xercesc::DOMNode* pToAuthorRef =
pToAttr->getNamedItem(xercesc::XMLString::transcode("AuthorRef"));

	xercesc::DOMDocument* pToDocument = pToAuthorRef->getOwnerDocument();

	xercesc::DOMElement* pToAuthor =
pToDocument->getElementById(pToAuthorRef->getNodeValue());


XML Document:

	...
	<AUTHOR id='_1'>
		<SHORTNAME>Rz</SHORTNAME>
		...
	</AUTHOR>
	...
	<REVISION AuthorRef='_1'>
		...
	</REVISION>




XML Schema:

	<xs:element name="AUTHOR">
		<xs:complexType>
			<xs:sequence>
				<xs:element ref="SHORTNAME"/>
				...
			</xs:sequence>
			<xs:attribute name="id" type="xs:ID" use="required"/>
		</xs:complexType>
	</xs:element>
	...
	<xs:element name="REVISION">
		<xs:complexType>
			<xs:sequence>
			...
			</xs:sequence>
			<xs:attribute name="AuthorRef" type="xs:IDREF" use="required"/>
		</xs:complexType>
	</xs:element>
 ____________________________________

 Mirko Braun
 Automotive Electronics Tools
 Softing AG
 Richard-Reitzner-Allee 6
 D-85540 Haar
 Tel:   +49 (0) 89 / 456 56 - 465
 Fax:   +49 (0) 89 / 456 56 - 499
 mailto:mirko.braun@softing.com
 http://www.softing.com
 ____________________________________


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


AW: problem with getElementById()

Posted by Mirko Braun <tb...@Softing.com>.
Hi to all,

thank you for your answers.
I think it was a problem of both the connection of the XML-file
with the Schema and the use of the setFeature() method.
Now it works.
Thank you.

Best regards, Mirko

> -----Ursprüngliche Nachricht-----
> Von: Denny Vrandecic [mailto:denny@nodix.de]
> Gesendet: Donnerstag, 11. Dezember 2003 14:00
> An: xerces-c-dev@xml.apache.org; tbm@softing.com
> Betreff: Re: problem with getElementById()
>
>
> Hi Mirko,
>
> just a little question, although I hope someone else will answer more
> competently to your problem:
>
> are you sure you connected the XML-file properly with the Schema
> file, i.e.
> does the DOM-Parser have the ability to utilize the information
> given in the
> Schema? This doesn't show in your example code.
> getElementsById can be used if and only if the parser knows about the
> Schema, otherwise he has no idea of ID-type-attributes.
>
> Best regards,
> Denny
>
> ----- Original Message -----
> From: "Mirko Braun" <tb...@Softing.com>
> To: <xe...@xml.apache.org>
> Sent: Thursday, December 11, 2003 10:49 AM
> Subject: problem with getElementById()
>
>
> >
> >  Hi to all,
> >
> >  i,m using the Xerces 2.3.0 to parse an XML-Document validating
> against a
> > Schema.
> >  When using the method getElementById() to get a node referenced by an
> IDREF
> > (see code below)
> >  a NULL-Pointer is given back. I'm sure that the ID is unique within the
> XML
> > Document.
> >
> >  Is their any special feature i have to set according to the
> use of Schema
> > and Xerces?
> >
> >  Can anybody help me? Thanks in advance.
> >
> >  Mirko
> >
> >
> >
> >
> >
> > C++ code:
> >
> > xercesc::DOMNode* pToDOMNode = oRevision.GetDOMNode();
> >
> > xercesc::DOMNamedNodeMap* pToAttr = pToDOMNode->getAttributes();
> >
> > xercesc::DOMNode* pToAuthorRef =
> > pToAttr->getNamedItem(xercesc::XMLString::transcode("AuthorRef"));
> >
> > xercesc::DOMDocument* pToDocument = pToAuthorRef->getOwnerDocument();
> >
> > xercesc::DOMElement* pToAuthor =
> > pToDocument->getElementById(pToAuthorRef->getNodeValue());
> >
> >
> > XML Document:
> >
> > ...
> > <AUTHOR id='_1'>
> > <SHORTNAME>Rz</SHORTNAME>
> > ...
> > </AUTHOR>
> > ...
> > <REVISION AuthorRef='_1'>
> > ...
> > </REVISION>
> >
> >
> >
> >
> > XML Schema:
> >
> > <xs:element name="AUTHOR">
> > <xs:complexType>
> > <xs:sequence>
> > <xs:element ref="SHORTNAME"/>
> > ...
> > </xs:sequence>
> > <xs:attribute name="id" type="xs:ID" use="required"/>
> > </xs:complexType>
> > </xs:element>
> > ...
> > <xs:element name="REVISION">
> > <xs:complexType>
> > <xs:sequence>
> > ...
> > </xs:sequence>
> > <xs:attribute name="AuthorRef" type="xs:IDREF" use="required"/>
> > </xs:complexType>
> > </xs:element>
> >  ____________________________________
> >
> >  Mirko Braun
> >  Automotive Electronics Tools
> >  Softing AG
> >  Richard-Reitzner-Allee 6
> >  D-85540 Haar
> >  Tel:   +49 (0) 89 / 456 56 - 465
> >  Fax:   +49 (0) 89 / 456 56 - 499
> >  mailto:mirko.braun@softing.com
> >  http://www.softing.com
> >  ____________________________________
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> > For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org


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


Re: problem with getElementById()

Posted by Denny Vrandecic <de...@nodix.de>.
Hi Mirko,

just a little question, although I hope someone else will answer more
competently to your problem:

are you sure you connected the XML-file properly with the Schema file, i.e.
does the DOM-Parser have the ability to utilize the information given in the
Schema? This doesn't show in your example code.
getElementsById can be used if and only if the parser knows about the
Schema, otherwise he has no idea of ID-type-attributes.

Best regards,
Denny

----- Original Message ----- 
From: "Mirko Braun" <tb...@Softing.com>
To: <xe...@xml.apache.org>
Sent: Thursday, December 11, 2003 10:49 AM
Subject: problem with getElementById()


>
>  Hi to all,
>
>  i,m using the Xerces 2.3.0 to parse an XML-Document validating against a
> Schema.
>  When using the method getElementById() to get a node referenced by an
IDREF
> (see code below)
>  a NULL-Pointer is given back. I'm sure that the ID is unique within the
XML
> Document.
>
>  Is their any special feature i have to set according to the use of Schema
> and Xerces?
>
>  Can anybody help me? Thanks in advance.
>
>  Mirko
>
>
>
>
>
> C++ code:
>
> xercesc::DOMNode* pToDOMNode = oRevision.GetDOMNode();
>
> xercesc::DOMNamedNodeMap* pToAttr = pToDOMNode->getAttributes();
>
> xercesc::DOMNode* pToAuthorRef =
> pToAttr->getNamedItem(xercesc::XMLString::transcode("AuthorRef"));
>
> xercesc::DOMDocument* pToDocument = pToAuthorRef->getOwnerDocument();
>
> xercesc::DOMElement* pToAuthor =
> pToDocument->getElementById(pToAuthorRef->getNodeValue());
>
>
> XML Document:
>
> ...
> <AUTHOR id='_1'>
> <SHORTNAME>Rz</SHORTNAME>
> ...
> </AUTHOR>
> ...
> <REVISION AuthorRef='_1'>
> ...
> </REVISION>
>
>
>
>
> XML Schema:
>
> <xs:element name="AUTHOR">
> <xs:complexType>
> <xs:sequence>
> <xs:element ref="SHORTNAME"/>
> ...
> </xs:sequence>
> <xs:attribute name="id" type="xs:ID" use="required"/>
> </xs:complexType>
> </xs:element>
> ...
> <xs:element name="REVISION">
> <xs:complexType>
> <xs:sequence>
> ...
> </xs:sequence>
> <xs:attribute name="AuthorRef" type="xs:IDREF" use="required"/>
> </xs:complexType>
> </xs:element>
>  ____________________________________
>
>  Mirko Braun
>  Automotive Electronics Tools
>  Softing AG
>  Richard-Reitzner-Allee 6
>  D-85540 Haar
>  Tel:   +49 (0) 89 / 456 56 - 465
>  Fax:   +49 (0) 89 / 456 56 - 499
>  mailto:mirko.braun@softing.com
>  http://www.softing.com
>  ____________________________________
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
> For additional commands, e-mail: xerces-c-dev-help@xml.apache.org
>


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