1

I have this xml:

InputStream is = new ByteArrayInputStream(
        "<data:RobCtiAifoData xmlns:data=\"urn:cz:isvs:rob:schemas:RobDotazyData:v1\" xmlns:reg=\"urn:cz:isvs:reg:schemas:RegTypy:v1\" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:cz:isvs:rob:schemas:RobUnivDotazy:v1\"><data:Aifo a=\"b\">1</data:Aifo><data:VyuzitiPoskytnuti>vyuziti</data:VyuzitiPoskytnuti> </data:RobCtiAifoData>"
                .getBytes());

// InputStream is = new ByteArrayInputStream(xml.getBytes());
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document document = db.parse(is);
Node node = document.getDocumentElement();

when wanna get name of element without namespace so I wanna call substring of name of element withou prefix

node.getNodeName() gives me data:VyuzitiPoskytnuti and node.getNamespaceURI() or node.getPrefix() gives me just null. So how I can get prefix of node ?

1
  • 3
    "when wanna get name of element without namespace so I wanna call substring of name of element withou prefix" - that's completely incomprehensible. Commented May 15, 2012 at 11:21

1 Answer 1

5

Try enabling namespace support:

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();

From the JavaDoc for setNamespaceAware:

Specifies that the parser produced by this code will provide support for XML namespaces. By default the value of this is set to false

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.