XSD 1.1 assert test containing single quote - xsd

Anybody got an idea why the following won't work? The xsd is validated with Xerces
<xs:element name="myElement">
<xs:complexType>
<xs:complexContent>
<xs:extension base="myElementType">
<xs:assert test="firstname = 'George' and lastName = 'Mc&apos;Falrland'" />
</xs:extension>
</xs:complexContent>
</xs:complexType>
</xs:element>
The error hits when i use the single quote &apos; entity...
Thanks

Your problem is related to XPath string literals, as XSD 1.1 uses XPath 2.0 you can escape an apostrophe or quotes inside a string literal by writing the delimiter two times, so you can use:
<xs:assert test="firstname = 'George' and lastName = 'Mc''Falrland'" />
For more info you can use XPath 2.0 specs, section Literals:
If the literal is delimited by apostrophes, two adjacent apostrophes
within the literal are interpreted as a single apostrophe. Similarly,
if the literal is delimited by quotation marks, two adjacent quotation
marks within the literal are interpreted as one quotation mark.

Related

base64binary to string with XQUERY

With Oracle ESB 11g, I need transform the structure of a webservice, but I have a problem with xml type, the source webservice has a type base64binary but my mockup is type string.
Source type
<xsd:element
name="MyDocument"
maxOccurs="1"
minOccurs="0"
type="xsd:base64Binary"
></xsd:element>
Destination type
<xs:element name="myBase64file" type="xs:string" minOccurs="0"/>
Why destination is String?? because my mockup in Java return a String
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("doc3.pdf");
byte[] bytes = IOUtils.toByteArray(stream);
byte[] bytes64 = Base64.encodeBase64(bytes);
myBase64file = new String(bytes64);
But now the real service returns base64binary :(
With oepe (Eclipse more plugins for Oracle OSB) in XQuery Mapper I Tried put a hard transformation like this
{
for $MyDocument in $MyData/ns2:MyDocument
return <myBase64file>{ data($MyDocument) }</myBase64file>
}
Is this the correct way?
I think to achieve your goal it's necessary to use the XQuery because you want to change the element name from myDocument to myBase64file, even if your destination element type was xs:base64Binary you need to execute your XQuery.
However a xs:base64Binary representation is basically a string limited to 65 alphabet characters: a-z, A-Z, 0-9, the plus sign (+), the forward slash (/) and the equal sign (=), together with the space character (#x20) (base64Binary), so you can think that xs:base64binary is an xs:string with an xs:restriction where you can only use the characters described above. Therefore if you prefer to have a xs:base64Binary instead of xs:string you can change your destination type to xs:base64Binary:
<xs:element name="myBase64file" type="xs:base64Binary" minOccurs="0"/>
and your java mockup code fits perfect this type because you are encoding your data to base64 and then returning as string.
Hope this helps,

Append literal string (plain text) to XPath result

Is there a way to append a literal string to whatever an XPath expression gets you?
e.g. from following XML:
<root>
<select>I am</select>
</root>
I would like to produce:
I am a literal
purely with XPath. What do I add to /root/select to get what I want? Important: XPath 1.0 solution required! I'm not using XSLT.
Any reason you can't simply concat() 'a literal' to the end?
Something like: concat( string(/some/selector) , ' some literal' )?

Count character ocurrences in a string in MSBuild

What's the easiest way to count the number of times a character ('\' in my case) appears in a string using MSBuild? I tried using Split(\) to no avail.
MsBuild 4.0 allows the use of property functions http://msdn.microsoft.com/en-us/library/dd633440.aspx
You can use this to split the string. You must then substract the length by 1 to get the occurrence count.
<Target Name="SplitCount">
<PropertyGroup>
<path>test\document\home</path>
</PropertyGroup>
<PropertyGroup>
<test>$(path.Split('\').length)</test>
</PropertyGroup>
<Message Text="occurrence count: $([MSBuild]::Subtract($(test), 1))"><Message>
</Target>
In the MSBuild Community Tasks, there is a RegexMatch task that would give you a list, which you could then count perhaps.
Another option would be to write your own custom task. Then add a bit of Linq like so:
string input = "This \\ is \\ a \\ test";
var items = (from c in input where c == '\\' select c).ToList();
var count = items.Count;

Deserialize XMLDocument with encoded characters in attribute names

I'm Trying to deserialize xml data into an object with c#. I have always done this using the .NET deserialize method, and that has worked well for most of what I have needed.
Now though, I have XML that is created by Sharepoint and the attribute names of the data I need to deserialize have encoded caracters, namely:
*space, º, ç ã, :, * and a hyphen as
x0020, x00ba, x007a, x00e3, x003a and x002d respectivly
I'm trying to figure out what I have to put in the attributeName parameter in the properties XmlAttribute
x0020 converts to a space well, so, for instance, I can use
[XmlAttribute(AttributeName = "ows_Nome Completo")]
to read
ows_Nome_x0020_Completo="MARIA..."
On The other hand, neither
[XmlAttribute(AttributeName = "ows_Motiva_x00e7__x00e3_o_x003a_")]
nor
[XmlAttribute(AttributeName = "ows_Motivação_x003a_")]
nor
[XmlAttribute(AttributeName = "ows_Motivação:")]
allow me to read
ows_Motiva_x00e7__x00e3_o_x003a_="text to read..."
With the first two I get no value returned, and the third gives me a runtime error for invalid caracters (the colon).
Anyway to get this working with .NET Deserialize, or do I have to build a specific deserializer for this?
Thanks!
What you are looking at (the "cryptic" data) is called XML entities. It's used by SharePoint to safekeep attribute names and similar elements.
There are a few ways of dealing with this, the most elegant ways to solve it is by extracting the List schema and match the element towards the schema. The schema contain all meta-data about your list data. A polished example of a Schema can be seen below or here http://www.bendsoft.com/documentation/camelot-php-tools/1_5/packets/schema-and-content-packets/schemas/example-list-view-schema/
If you don't want to walk that path you could start here http://msdn.microsoft.com/en-us/library/35577sxd.aspx
<Field Name="ContentType">
<ID>c042a256-787d-4a6f-8a8a-cf6ab767f12d</ID>
<DisplayName>Content Type</DisplayName>
<Type>Text</Type>
<Required>False</Required>
<ReadOnly>True</ReadOnly>
<PrimaryKey>False</PrimaryKey>
<Percentage>False</Percentage>
<RichText>False</RichText>
<VisibleInView>True</VisibleInView>
<AppendOnly>False</AppendOnly>
<FillInChoice>False</FillInChoice>
<HTMLEncode>False</HTMLEncode>
<Mult>False</Mult>
<Filterable>True</Filterable>
<Sortable>True</Sortable>
<Group>_Hidden</Group>
</Field>
<Field Name="Title">
<ID>fa564e0f-0c70-4ab9-b863-0177e6ddd247</ID>
<DisplayName>Title</DisplayName>
<Type>Text</Type>
<Required>True</Required>
<ReadOnly>False</ReadOnly>
<PrimaryKey>False</PrimaryKey>
<Percentage>False</Percentage>
<RichText>False</RichText>
<VisibleInView>True</VisibleInView>
<AppendOnly>False</AppendOnly>
<FillInChoice>False</FillInChoice>
<HTMLEncode>False</HTMLEncode>
<Mult>False</Mult>
<Filterable>True</Filterable>
<Sortable>True</Sortable>
</Field>
<Field>
...
</Field>
Well... I guess I kind of hacked a way around, which works for now. Just replaced the _x***_ charecters for nothing, and corrected the XmlAttributes acordingly. This replacement is done by first loading the xml as a string, then replacing, then loading the "clean" text as XML.
But I wopuld still like to know if it is possible to use some XmlAttribute Name for a more direct approach...
Try using System.Xml; XmlConvert.EncodeName and XmlConvert.DecodeName
I use a simply function to get the NameCol:
private string getNameCol(string colName) {
if (colName.Length > 20) colName = colName.Substring(0, 20);
return System.Xml.XmlConvert.EncodeName(colName);
}
I'm already searching for replace characters like á, é, í, ó, ú. EncodeName doesn't convert this characters.
Can use Replace:
.Replace("ó","_x00f3_").Replace("á","_x00e1_")

How can I repeatedly match from A until B in VIM?

I need to get all text between <Annotation> and </Annotation>, where a word MATCH occurs. How can I do it in VIM?
<Annotation about="MATCH UNTIL </Annotation> " timestamp="0x000463e92263dd4a" href=" 5raS5maS90ZWh0YXZha29rb2VsbWEvbGFza2FyaS8QyrqPk5L9mAI">
<Label name="las" />
<Label name="_cse_6sbbohxmd_c" />
<AdditionalData attribute="original_url" value="MATCH UNTIL </Annotation> " />
</Annotation>
<Annotation about="NO MATCH" href=" Cjl3aWtpLmhlbHNpbmtpLmZpL2Rpc3BsYXkvbWF0aHN0YXRLdXJzc2l0L0thaWtraStrdXJzc2l0LyoQh_HGoJH9mAI">
<Label name="_cse_6sbbohxmd_c" />
<Label name="courses" />
<Label name="kurssit" />
<AdditionalData attribute="original_url" value="NO MATCH" />
</Annotation>
<Annotation about="MATCH UNTIL </ANNOTATION> " score="1" timestamp="0x000463e90f8eed5c" href="CiZtYXRoc3RhdC5oZWx zaW5raS5maS90ZWh0YXZha29rb2VsbWEvKhDc2rv8kP2YAg">
<Label name="_cse_6sbbohxmd_c" />
<Label name="exercises_without_solutions" />
<Label name="tehtäväkokoelma" />
<AdditionalData attribute="original_url" value="MATCH UNTIL </ANNOTATION>" />
</Annotation>
First, a disclaimer: Any attempt to slice and dice XML with regular expressions is fragile; a real XML parser would do better.
The pattern:
\(<Annotation\(\s*\w\+="[^"]\{-}"\s\{-}\)*>\)\#<=\(\(<\/Annotation\)\#!\_.\)\{-}"MATCH\_.\{-}\(<\/Annotation>\)\#=
Let's break it down...
Group 1 is <Annotation\(\s*\w\+="[^"]\{-}"\s\{-}\)*>. It matches the start-tag of the Attribute element. Group 2, which is embedded in Group 1, matches an attribute and may be repeated 0 or more times.
Group 2 is \s*\w\+="[^"]\{-}"\s\{-}. Most of these pieces are commonly used; the most unusual is \{-}, which means non-greedy repetition (*? in Perl-compatible regular expressions). The non-greedy whitespace match at the end is important for performance; without it, Vim will try every possible way to split the whitespace between attributes between the \s* at the end of Group 2 and the \s* at the beginning of the next occurrence of Group 2.
Group 1 is followed by \#<=. This is a zero-width positive look-behind. It prevents the start-tag from being included in the matched text (e.g., for s///).
Group 3 is \(<\/Annotation\)\#!\_.. It includes Group 4, which matches the beginning of the Attribute end-tag. The \#! is a zero-width negative look-ahead and \_. matches any character (including newlines). Together, this groups matches at any character except where the Attribute end-tag starts. Group 3 is followed by a non-greedy repetition marker \{-} so that it matches the smallest block of text before MATCH. If you were to use \_. instead of Group 3, the matched text could include the end-tag of an Annotation element that did not include MATCH and continue through into the next Annotation element with MATCH. (Try it.)
The next bit is straightforward: Find MATCH and a minimal number of other characters before the end-tag.
Group 5 is easy: It's the end tag. \#= is a zero-width positive look-ahead, which is included here for the same reason as the \#<= for the start-tag. We have to repeat <\/Attribute rather than use \4 because groups with zero-width modifiers aren't captured.
Does it have to be done within vim? Could you cheat, and open a second window where you pipe something into more/less that tells you what line number to go to within vim?
-- edit --
I have never done a multi-line match/search in vi[m]. However, to cheat in another window:
perl -n -e 'if ( /<tag/ .. /<\/tag/)' -e '{ print "$.:$_"; }' file.xml | less
will show the elements/blocks for "tag" (or other longer matching names), with line numbers, in less, and you can then search for the other text within each block.
Close enough?
-- edit --
within "less", type
/MATCH
to search for occurrences of MATCH. On the left margin will be the line number where that instance (within the targeted element/tags) is.
within vi[m], type
:n
where "n" is the desired line number.
Of course, if what you really wanted to do was some kind of search/yank/replace, it's more complicated. At that point, awk / perl / ruby (or something similar which meets your tastes ... or xsl?) is really the tool you should be using for the transformation.

Resources