well-formed

Specifying root and child nodes with JAXB

折月煮酒 提交于 2019-12-02 10:44:10
Staying within JAXB how would I refactor MyNote so that it conforms to: <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don't forget me this weekend!</body> </note> Which is well formed but not valid, to my understanding. Current output: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <MyNotes> <Note> <note>XY3Z1RGEO9W79LALCS</note> <to>LJAY9RNMUGGENGNND9</to> <from>GOVSHVZ3GJWC864L7X</from> <heading>EX6LGVE5LGY4A6B9SK</heading> <body>L95WYQNMEU1MFDRBG4</body> </Note> </MyNotes> which is too flat, rather than nested as the example . I believe this makes note

Is this valid YAML?

谁说我不能喝 提交于 2019-12-01 18:36:36
So for my text parsing in C# question , I got directed at YAML. I'm hitting a wall with this library I was recommended, so this is a quickie. heading: name: A name taco: Yes age: 32 heading: name: Another name taco: No age: 27 And so on. Is that valid? Partially. YAML supports the notion of multiple consecutive "documents". If this is what you are trying to do here, then yes, it is correct - you have two documents (or document fragments). To make it more explicit, you should separate them with three dashes, like this: --- heading: name: A name taco: Yes age: 32 --- heading: name: Another name

Validating against a Schema with JAXB

痴心易碎 提交于 2019-11-30 17:47:37
I've been looking for solutions to this problem for far too long considering how easy it sounds so I've come for some help. I have an XML Schema which I have used with xjc to create my JAXB binding. This works fine when the XML is well formed. Unfortunately it also doesn't complain when the XML is not well formed. I cannot figure out how to do proper full validation against the schema when I try to unmarshall an XML file. I have managed to use a ValidationEventCollector to handle events, which works for XML parsing errors such as mismatched tags but doesn't raise any events when there is a tag

Is a colon a legal first character in an XML tag name?

放肆的年华 提交于 2019-11-28 14:07:14
According to the W3C XML Recommendation , start tag-names have the definition: STag ::= '<' Name (S Attribute)* S? '>' ..where Name is: Name ::= NameStartChar (NameChar)* NameStartChar ::= ":" | [A-Z] | ... ..(n.b., states that a colon can appear as the first character) suggesting the following is a valid XML document: <?xml version="1.0" ?><:doc></:doc> ..but any parser I try this in shows the colon as a formatting error. Also, under Appendices B (though now a depreciated part of the document) it explicitly states: Characters ':' and '_' are allowed as name-start characters. ..and: <?xml

How to validate JSON in PHP?

拟墨画扇 提交于 2019-11-27 17:13:43
问题 Is there any way to check that a variable is a valid JSON string in PHP without using json_last_error() ? I don't have PHP 5.3.3. 回答1: $ob = json_decode($json); if($ob === null) { // $ob is null because the json cannot be decoded } 回答2: $data = json_decode($json_string); if (is_null($data)) { die("Something dun gone blowed up!"); } 回答3: If you want to check if your input is valid JSON, you might as well be interested in validating whether or not it follows a specific format, i.e a schema. In

Check well-formed XML without a try/catch?

耗尽温柔 提交于 2019-11-27 08:51:01
Does anyone know how I can check if a string contains well-formed XML without using something like XmlDocument.LoadXml() in a try/catch block? I've got input that may or may not be XML, and I want code that recognises that input may not be XML without relying on a try/catch, for both speed and on the general principle that non-exceptional circumstances shouldn't raise exceptions. I currently have code that does this; private bool IsValidXML(string value) { try { // Check we actually have a value if (string.IsNullOrEmpty(value) == false) { // Try to load the value into a document XmlDocument

Is a colon a legal first character in an XML tag name?

雨燕双飞 提交于 2019-11-27 08:10:14
问题 According to the W3C XML Recommendation, start tag-names have the definition: STag ::= '<' Name (S Attribute)* S? '>' ..where Name is: Name ::= NameStartChar (NameChar)* NameStartChar ::= ":" | [A-Z] | ... ..(n.b., states that a colon can appear as the first character) suggesting the following is a valid XML document: <?xml version="1.0" ?><:doc></:doc> ..but any parser I try this in shows the colon as a formatting error. Also, under Appendices B (though now a depreciated part of the document

Check well-formed XML without a try/catch?

喜你入骨 提交于 2019-11-26 14:19:31
问题 Does anyone know how I can check if a string contains well-formed XML without using something like XmlDocument.LoadXml() in a try/catch block? I've got input that may or may not be XML, and I want code that recognises that input may not be XML without relying on a try/catch, for both speed and on the general principle that non-exceptional circumstances shouldn't raise exceptions. I currently have code that does this; private bool IsValidXML(string value) { try { // Check we actually have a