You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Omar Hamed <om...@gmail.com> on 2009/11/18 08:57:18 UTC

Can't get type of the newly added elements

Hi,
     I have a problem that I can't re-parse the xml document after adding
nodes to it so that I can retrieve the new elements type.

here is the code:
public static void main(String[] args){

     DocumentBuilderFactory parserFactory =
DocumentBuilderFactory.newInstance();
     SchemaFactory factory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);

            Source schemaFile = new StreamSource(new File("test.xsd"));
            Schema schema = factory.newSchema(schemaFile);

            parserFactory.setSchema(schema);

            DocumentBuilder parser = parserFactory.newDocumentBuilder();
            Document document = parser.parse(new File("test.xml"));


            Node promoTag =
document.getElementsByTagName("promotion_period").item(0); // get element

            Element endElm = document.createElement("end_date");            //
add new element
            endElm.setTextContent("2007-05-10");
            promoTag.appendChild(endElm);

            ((Element)
document.getElementsByTagName("end_date").item(0)).getSchemaTypeInfo().getTypeName();
// [1] returns null
}

At point #1: I think I need something like re-parse or re-validate the
document so that I can attach the added node with its type.

I have the same issue if I'm working with the XERCES ElementPSVI.

I don't know what is missing or how can I do that.

Thanks in advance
Omar Mostafa