PriegoProrews
New Member
I want to add some data to a xml file like:\[code\]<people> <person name="Jo"> <number>0</number> ... </person> <person name="Steve"> <number>5</number> ... </person></people>\[/code\]where name is an id value. I use this expression because I need to know if some child have the same name I want to add so I only need to write:\[code\]Document doc = docBuilder.parse(file);Element person = doc.getElementById("myname");\[/code\]so I don't need to do loops with all nodechild. My problem is that for this I need to define a schema but Java returns me an error in the forth line of the following code:\[code\]DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();docFactory.setNamespaceAware(true);docFactory.setValidating(true);docFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema"); docFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaSource", "my schema in a string"); DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); \[/code\]the error is:java.lang.IllegalArgumentException: http://java.sun.com/xml/jaxp/properties/schemaLanguageand I have imported:\[code\] import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.w3c.dom.Element;\[/code\]why do I have this error? Of course I can do this using name as a child and reading all in a NodeList and then using a loop but I think this way has a better performance.PS: I insert the schema as a string. I don't know if I will have an error because the error is in the previous line but in case I need to have the schema in a file, where do I save the file? In raw folder?