XPath Select all elements name of which NOT starts with Capital letter - xpath

I Have Schema Name.xsd, it's part of it,need help in framing the query in XPath that
<xsd:complexType name="GetWalletItemBO">
<xsd:sequence>
<xsd:element minOccurs="1" name="paymentOptionId">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="50" />
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
my basic query is like //*[starts-with(name(),'**here I need to put my condition**')]
I have to check that xsd:complexType name starts with Capital letter GetWalletItemBO and not like getWalletItemBO , and on the same way to check that <xsd:element name= starts with small letter paymentOptionId not like PaymentOptionId . *So I try find all elements that HAVE BAD input, don't appropriate to my conditions , that's starts with small letter in xsd:complexType name= ,and with Capital letter in xsd:element name= *.

I think you want:
//xs:complexType[matches(#name, '$\P{Lu}')]

Do not use name() but local-name() to get the name without namespace identifier. Then, split off the first letter and see if it is not contained in the capital letters:
//*[not(contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ', substring(local-name(.), 1, 1)))]

Related

Failure of conditional combination index in eXist-db range index

I encountered the following problems in eXist-db configuring range indexes to specify attributes that are worth indexing.
<collection xmlns="http://exist-db.org/collection-config/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<index>
<range>
<create qname="tei:term">
<condition attribute="type" value="main"/>
<field name="mainTerm" type="xs:string"/>
</create>
</range>
</index></collection>
Error occurred:"/db/system/config/db/range/collection.xconf cvc-complex-type.2.4.a: Invalid content was found starting with element 'condition'. One of '{"http://exist-db.org/collection-config/1.0":field}' is expected."
Please help me.
The error you are getting is a schema validation error, triggered by the presence of the <condition> element used by the recently introduced conditional combined index feature.
I've submitted a fix to the error, and for now, you can ignore the error. The schema validation error will not have any effect on the functionality.
General Configuration Structure and Syntax
Index configuration collection.xconf files are standard XML documents that have their elements and attributes defined by the eXist-db namespace http://exist-db.org/collection-config/1.0. The following example shows a configuration example:
<collection xmlns="http://exist-db.org/collection-config/1.0">
<index>
<!-- Full text index based on Lucene -->
<lucene>
<text qname="SPEECH">
<ignore qname="SPEAKER"/>
</text>
<text qname="TITLE"/>
</lucene>
<!-- Range indexes -->
<range>
<create qname="title" type="xs:string"/>
<create qname="author" type="xs:string"/>
<create qname="year" type="xs:integer"/>
</range>
<!-- N-gram indexes -->
<ngram qname="author"/>
<ngram qname="title"/>
</index>
</collection>
To use the new range index, wrap the range index definitions into a range element:
<collection xmlns="http://exist-db.org/collection-config/1.0">
<!--from Tamboti-->
<index xmlns:mods="http://www.loc.gov/mods/v3">
<lucene>
<text qname="mods:title"/>
</lucene>
<!-- Range indexes -->
<range>
<create qname="mods:namePart" type="xs:string" case="no"/>
<create qname="mods:dateIssued" type="xs:string"/>
<create qname="#ID" type="xs:string"/>
</range>
</index>
</collection>
Conditional combined indexes
For combined indexes, you can specify conditions to restrict the values being indexed to those contained in elements that have an attribute meeting certain criteria:
<range>
<create qname="tei:term">
<condition attribute="type" value="main"/>
<field name="mainTerm" type="xs:string"/>
</create>
</range>
This will only index the value of the tei:term element if it has an attribute named type with the value main. Multiple conditions can be specified in an index definition, in which case all conditions need to match in order for the value to be indexed.
Make sure you have a valid xml. For further details, you can read the documentation here: https://exist-db.org/exist/apps/doc/newrangeindex.xml

Can I get xpath count value in robot framework

Assume the following XML:
<data>
<node id="1" />
<node id="2" />
<node id="12" />
<node id="16" />
</data>
This xpath expression should be valid:
count(//node)
.. and should produce the number 4
I'm new to robot frameworks. Is it possible to use this xpath in robot framework?
for example something like:
${value}= Get something something source=${xml} xpath=count(//node)
The one below works but I would like the xpath to produce the end value, not a list.
#{nodelist}= Get Elements ${xml} xpath=node
Length Should Be ${nodelist} 4
Edit
I know that I can count the nodes in a list of nodes. However, I would like to get the absolute value (integer or string) using xpath. Now I need to write different code depending on if the xpath result is a node, list or attribute when the xpath could theoretically produce the final value.
You can use the Get Element Count Keyword it returns the number of elements matching the locator
You can do something as simple as this
${count} = Get Element Count name:div_name
Should Be True ${count} > 2
For more info on Keywords Have a look at this Keyword Page
When working with XML it is generally best to use the XML library. In the below example you'll find a solution for counting the elements using the XML library Get Element Count.
data.xml
<data>
<node id="1" />
<node id="2" />
<node id="12" />
<node id="16" />
</data>
Testcase.robot
*** Settings ***
Library XML
Library OperatingSystem
*** Test Cases ***
TC
${xml} Get File ./data.xml
${count} Get Element Count ${xml} xpath=node
Should Be Equal As Integers ${count} ${4}

Why is VisualStudio 2017 telling me "...element is not supported in this context"?

MCVE:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
targetNamespace="http://versionschema.org/xmlns/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:vs="http://versionschema.org/xmlns/"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<xsd:element name="VersionSchema" type="vs:VersionSchema"/>
<xsd:complexType name="VersionSchema" minOccurs="1" maxOccurs="1">
<!-- VS says: "minOccurs and maxOccurs not allowed ^^^^ -->
<xsd:element name="Field" minOccurs="1" maxOccurs="unbounded">
<!-- ^^^ VS says: The 'http://www.w3.org/2001/XMLSchema:element' is not supported in this context -->
</xsd:element>
</xsd:complexType>
</xsd:schema>
Referring to https://www.w3.org/TR/xmlschema-0/#POSchema, I don't see why it's complaining. Any ideas whether or what it is I am doing wrong here?
Note that it is my goal to write this up such that there can be only one VersionSchema object in an XML file.
Your are thinking about this from a programming language perspective in which you would add fields to a class or type by placing them as elements inside of the container.
For XML Schemas this is not true. The reason for this is that in its most strict definition XML is order dependent.
You can write yourself a schema which accepts the following XML.
<Root>
<Element/>
<Test/>
</Root>
But rejects a very similiar XML Structure:
<Root>
<Test/>
<Element/>
</Root>
One of the reasons you can do so is because a more strict XML schema is easier to guard against attacks and malicious input. It is therefore always required to specifiy in the XML Schema wether or not the order in which elements appear matter. This is why an element such as the xsd:sequence is required. Note that this can quickly become a tripwire for your serialization and deserialization.
Your orignal XML could therefore be stated as follows but might be stated differently depending on your exact use case
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema
targetNamespace="http://versionschema.org/xmlns/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:vs="http://versionschema.org/xmlns/"
elementFormDefault="unqualified"
attributeFormDefault="unqualified">
<xsd:element name="VersionSchema" type="vs:VersionSchema"/>
<xsd:complexType name="VersionSchema">
<xsd:sequence minOccurs="1" maxOccurs="1">
<xsd:element name="Field" minOccurs="1" maxOccurs="unbounded"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
The relevant sections would be 3.4 Complex Type Definitions and 2.2.3 Model Group Components. It states that
The XML representation for a complex type definition schema component
is a <complexType> element information item. [...] Content:
(annotation?, (simpleContent | complexContent | (openContent?, (group| all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?), assert*)))
Note that in order to place an <element> into the complex type you either have to use complexContent, a group or modelgroup elements like all, choice or sequence. It is the same for complexContent which cannot contain <element> but only extension which can only contain
(annotation?, openContent?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?), assert*))
[...]There are three varieties of model group:
Sequence (the element information items match the particles in
sequential order); Conjunction (the element information items match
the particles, in any order); Disjunction (the element information
items match one or more of the particles). Model Group, a kind of Term
[...] specifies a sequential (sequence), disjunctive (choice) or
conjunctive (all) interpretation of the {particles}. This in turn
determines whether the element information item [children] validated
by the model group must:
(sequence) correspond, in order, to the specified {particles};
(choice) correspond to exactly one of the specified {particles}; (all)
correspond to the specified {particles}. The elements can occur in any
order.
Even if stated slightly confusing in the model group section, a model group can itself only host the following content
(annotation?, (all | choice | sequence)?)
Which pretty much boils down to having to use all, choice and sequence when you would like to use <element>.
all : (annotation?, (element | any | group)*)
choice : (annotation?, (element | group | choice | sequence | any)*)
sequence: (annotation?, (element | group | choice | sequence | any)*)

Appending multiple strings in Oracle SOA Suit in a BPEL process

I'm new to the Oracle SOA Suite and I have created a basic BPEL process that allows you to create a "User" with some basic values.
XSD:
//INPUT
<element name="User">
<complexType>
<sequence>
<element name="First_Name" type="string"/>
<element name="Last_Name" type="string"/>
<element name="Age" type="string"/>
<element name="DOB" type="string"/>
</sequence>
</complexType>
</element>
// String to output
<element name="processResponse">
<complexType>
<sequence>
<element name="Output" type="string"/>
</sequence>
</complexType>
</element>
So using this XSD I want to be able to create a user, and append all the values together and create a response/reply with my synchronous BPEL process.
I've tried simply adding all the values together using the '+' operation but doesn't work as it tries to cast it it a integer, so it seems and the value comes out as "Jon NaN".
<copy>
<from>concat("Hello! ", $inputVariable.payload/ns1:Last_Namel)</from>
<to>$outputVariable.payload</to>
</copy>
I've also tried to use multiple concat's but it get's real ugly real quick, and something i would like to avoid is messy code.
So as a summary i want to be able to take all the input values (First Name, Last Name, Age, DOB) and convert them into a nice string with some padding and extra hard coded strings to show a nice message at the end.
Give all the values which you require to be concatenated comma separated in the concat() function:
<from>concat('Hello! ', $inputVariable.payload/ns1:Last_Name,' ',$inputVariable.payload/ns1:First_Name,' ',$inputVariable.payload/ns1:Age,' ',$inputVariable.payload/ns1:DOB)</from>
<to>$outputVariable.payload/Output</to>

Declaring enumeration on elements in DTD [duplicate]

I'm constructing a DTD which has a fuel_system element.
I want to restrict the text between <fuel_system> tag. It must be only carbureted or fuel-injected. How can I do this?
I don't mention something like this = > attribute type (carbureted, fuel-injected), because I want to force this rule in <fuel_system> tags, not the attribute of fuel_system.
when defining an element in a DTD, there is no way to restrict the text inside the element. you can only tell what other element (child elements) it might contain and their order, or you can tell that the element contains text, or a mixture of the 2.
so, basically you have 2 options for restricting the <fuel-system>: either declare it as an attribute (<fuel-system type="fuel-injected"/>), or declare children elements <fuel-injected> and <carburated>. the choice between those 2 options depends on what you are trying to describe and what will change depending on the type of fuel-system.
(the grammar for the declaration of an element is defined here)
examples: first option, attributes
<!ELEMENT fuel-system EMPTY>
<!ATTLIST fuel-system (fuel-injected|carburated) #REQUIRED>
second option, child elements
<!ELEMENT fuel-system (fuel-injected|carburated)>
<!ELEMENT fuel-injected ...>
<!ELEMENT carburated ...>
Does it have to be a DTD? Is XML Schema an option?
Using XML Schema you can restrict element text to an enumerated list of values:
<xs:element name="fuel-system">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="fuel-injected"/>
<xs:enumeration value="carbourated"/>
</xs:restriction>
</xs:simpleType>
</xs:element>

Resources