开发者

regular expression to check if string is valid XML [closed]

It's difficult to tell what is being asked here. This question is amb开发者_StackOverflow社区iguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

I am looking java code to check if a string is valid XML.


It's not possible to validate XML with regular expressions. XML is not a regular language.

Use an XML parser to try to parse the string as XML or else validate the XML document against a schema, for example a DTD or XSD file.


you can check whether document or text is well-formed, by using a parser. i think this link will help you:

http://www.roseindia.net/xml/dom/DOMParserCheck.shtml

for string replace this line in the link:

InputSource is = new InputSource(xmlFile);

with

ByteArrayInputStream stringStream=new ByteArrayInputStream("XML Text".getBytes());

InputSource is=new InputSource(stringStream);

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜