I have some XML files that I need to batch process into SQL Server. The following Schema and XML sections outline an area I'm having trouble with.
<xs:complexType>
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="TextLine" type="xs:string" sql:field="AdvertLine" sql:relation="XmlAdvert" sql:relationship="XmlAdvert" />
<xs:element name="BreakPoint" sql:is-constant="1" />
</xs:choice>
</xs:sequence>
</xs:complexType>
<Advert>
<AdvertText>
<TextLine>Isuzu 4 X 4TRUCKMAN</TextLine>
<BreakPoint />
<TextLine>2.0TD, Red, 5 dr, 60,000 miles, MOT, 5 SEATER</TextLine>
<BreakPoint />
<TextLine>£2500</TextLine>
<BreakPoint />
<TextLine>01234 567890</TextLine>
</AdvertText>
</Advert>
But since xs:choice isn't supported in SQLXMLBulkload I wondered if there was another way of representing this as without the xs:choice section the xs:sequence is invalid as soon as it hits the second TextLine.
I'm not familiar with SQLXMLBulkload, but here are my thoughts:
I'm not sure if there's any relationship between adjacent TextLine and BreakPoint elements. Assuming that there isn't, then the simplest solution may be to use XSLT to transform the schema and data to eliminate the need for the choice.
Note that I've inserted maxOccurs="unbounded" on both elements. If that doesn't work, there's an alternate approach that should work; see below.
<xs:complexType>
<xs:sequence>
<xs:element name="TextLine" type="xs:string" sql:field="AdvertLine" sql:relation="XmlAdvert" sql:relationship="XmlAdvert" maxOccurs="unbounded"/>
<xs:element name="BreakPoint" sql:is-constant="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
The equivalent XML would be:
<Advert>
<AdvertText>
<TextLine>Isuzu 4 X 4TRUCKMAN</TextLine>
<TextLine>2.0TD, Red, 5 dr, 60,000 miles, MOT, 5 SEATER</TextLine>
<TextLine>£2500</TextLine>
<TextLine>01234 567890</TextLine>
<BreakPoint />
<BreakPoint />
<BreakPoint />
</AdvertText>
</Advert>
But for all I know, SQLXMLBulkload won't like that arrangement either. In that case, based only on your example XML, I would bet that it would accept this:
with the matching XML being:
<Advert>
<AdvertText>
<TextLines>
<TextLine>Isuzu 4 X 4TRUCKMAN</TextLine>
<TextLine>2.0TD, Red, 5 dr, 60,000 miles, MOT, 5 SEATER</TextLine>
<TextLine>£2500</TextLine>
<TextLine>01234 567890</TextLine>
</TextLines>
<BreakPoints>
<BreakPoint />
<BreakPoint />
<BreakPoint />
</BreakPoints>
</AdvertText>
</Advert>
That still leaves open the question of how to write the XSLT that you'd need, but perhaps it's a start.
Related
We are attempting to expose a new field to only two groups (of many) within a TFS team project. We would like to implement a rule to the WIT object for which multiple values would satisfy the issue.
We have tried nested..
<WHENNOT field="System.AreaId" value="1"/>
<WHENNOT field="System.AreaId" value="2"/>
repeated...
<WHENNOT field="System.AreaId" value="1">
</WHENNOT>
<WHENNOT field="System.AreaId" value="2">
</WHENNOT>
and some guesses to the syntax..
<WHENNOT field="System.AreaId" value="1 or 2"/>
<WHENNOT field="System.AreaId" value="1 || 2"/>
<WHENNOT field="System.AreaId" value="1, 2"/>
without achieving the intended result.
<FIELD name="Original Estimate" refname="Microsoft.VSTS.Scheduling.OriginalEstimate" type="Double" reportable="measure" formula="sum">
<HELPTEXT>Initial value for Remaining Work - set once, when work begins</HELPTEXT>
<WHENNOT field="System.AreaId" value="24">
<READONLY />
</WHENNOT>
<WHENNOT field="System.State" value="To Do">
<READONLY />
</WHENNOT>
<WHEN field="System.State" value="Done">
<REQUIRED />
</WHEN>
</FIELD>
We would like to show the field based on whether the WIT is associated with Area ID 1 or 2, but otherwise hide from all of others.
You can't combine 2 WHENNOT because they cancel each other.
You need to use <WHEN field="System.AreaId" value="{id}"> <READONLY> </WHEN>
with all the areas (unless 1 and 2).
I store a docx file in sql server database that contains negative number like -56653.
I installed Microsoft Filter Pack 2.0 and execute this code:
EXEC sp_fulltext_service 'update_languages';
EXEC sp_fulltext_service 'load_os_resources', 1;
EXEC sp_fulltext_service 'restart_all_fdhosts';
Then rebuild the Full Text Catalog multiple time, When search 56653, the query not found any things, but when search -56653 the query work fine.
SELECT *
FROM Files
WHERE
(CONTAINS([Files].[Content], '"56653"'))
Does somebody know what is the problem?
Finally I found the problem. Full text catalog not indexed content of table which inside a paragraph!
This mean the w:tbl tag move to outside of w:p tag.
<w:p w:rsidR="00E402AA" w:rsidP="00E402AA" w:rsidRDefault="00E402AA">
<w:pPr>
<w:bidi />
<w:spacing w:after="0" w:line="240" w:lineRule="auto" />
<w:jc w:val="both" />
<w:rPr>
<w:bCs />
<w:sz w:val="24" />
</w:rPr>
</w:pPr>
<w:r>
<w:rPr>
<w:bCs />
<w:sz w:val="24" />
</w:rPr>
</w:r>
<!-- Start Table -->
<w:tbl>
<w:tblPr>
<w:tblStyle w:val="TableGrid" />
<w:tblW w:w="5000" w:type="pct" />
</w:tblPr>
<w:tr>
<w:tc>
...
</w:tc>
</w:tr>
</w:tbl>
<!-- End Table -->
</w:p>
I have an xml like the following:
<table1>
<row>
<person>person1</person>
<value>10</value>
</row>
<row>
<person>person2</person>
<value>20</value>
</row>
<row>
<person>person1</person>
<value>5</value>
</row>
</table1>
<summaryTable>
<row>
<person>person1</person>
<value_total/>
</row>
<row>
<person>person2</person>
<value_total/>
</row>
</summaryTable>
With XForms 1 (there is no option to switch to XForms 2), using framework betterform, I want to calculate the values in the summary table, by doing the SUM of the rows in 'table1' that have the same person name. To do that I have the following binds:
<xf:bind id="bind_table1"
nodeset="table1" repeatableElement="row">
<xf:bind id="bind_head_table1" nodeset="head" />
<xf:bind id="bind_row_table1" nodeset="row">
<xf:bind id="bind_person" nodeset="person" type="xf:string" />
<xf:bind id="bind_value" nodeset="value" type="xf:integer" />
</xf:bind>
</xf:bind>
<xf:bind id="bind_summaryTable"
nodeset="summaryTable"
repeatableElement="row">
<xf:bind id="bind_head_summaryTable" nodeset="head" />
<xf:bind id="bind_row_summaryTable" nodeset="row">
<xf:bind id="bind_person_name" nodeset="person_name" type="xf:string" readonly="true"/>
<xf:bind id="bind_value_total" nodeset="value_total" type="xf:integer" readonly="true" calculate="SUM(//table1/row[person/text() = ../person_name/text()]/value)"/>
</xf:bind>
</xf:bind>
What I want to have at the end is the value_total for person1 = 15 and value_total for person2 = 20, but using this 'calculate' expression I'm getting 'NaN'. If I replace the calculate expression to compare with a literal String like:
<xf:bind id="bind_value_total" nodeset="value_total" type="xf:integer" readonly="true" calculate="SUM(//table1/row[person/text() = 'person1']/value)"/>
then I get as value_total 15 (the sum is correctly done). So it seems that the error is in the comparison expression person/text() = ../person_name/text() . Does someone have an idea about how should be the correct expression?
Thanks
Try the context() function in the calculate attribute to refer to the current node, like this:
<xf:bind nodeset="summaryTable/row/value_total" calculate="sum(//table1/row[person/text() = context()/../person/text()]/value)"/>
The context function gives you the current context node. If your bind references a nodeset with multiple nodes, it will be evaluated one time for every node, and that node is what context() returns.
It works for me with XSLTForms, maybe your version of betterForm supports it.
Version 11g Release 1 (11.1.1.7)
I have created the data sources in BIP with seperate single data set using a simple select * SQL for each data source.
The view sample data works fine.
The issue comes when trying to create a report template using BIP interactive format (xpt).
I create the data table and when I drag the column from left pane in to data table, a No Data Found error is all I get.
It is random since it works fine for other data sources with select * from same database and since the view sample data works in the data source the the chance the SQL is causing this error is nil.
I have recreated these data sources and error still occurs.
Think this is a bug with BIP?
edit: including SQL and generated xml for a data source, I can't share any names though.
SQL:
SELECT
*
FROM
view;
XML:
<output rootName="DATA_DS" uniqueRowName="false">
<nodeList name="data-structure">
<dataStructure tagName="DATA_DS">
<group name="G_1" label="G_1" source="zzz">
<element name="xxx" value="xxx" label="xxx" dataType="xsd:string" breakOrder=""
fieldOrder="1"/>
<element name="mmm" value="mmm" label="mmm" dataType="xsd:string"
breakOrder="" fieldOrder="2"/>
<element name="yyy" value="yyy" label="yyy" dataType="xsd:string" breakOrder=""
fieldOrder="3"/>
<element name="aaa" value="aaa" label="aaa" dataType="xsd:string" breakOrder=""
fieldOrder="4"/>
<element name="bbb" value="bbb" label="bbb" dataType="xsd:string" breakOrder=""
fieldOrder="5"/>
<element name="ccc" value="ccc" label="ccc" dataType="xsd:long" breakOrder=""
fieldOrder="6"/>
<element name="ddd" value="ddd" label="ddd" dataType="xsd:double" breakOrder=""
fieldOrder="7"/>
<element name="eee" value="eee" label="eee" dataType="xsd:string" breakOrder=""
fieldOrder="8"/>
<element name="fff" value="fff" label="fff" dataType="xsd:long" breakOrder=""
fieldOrder="9"/>
<element name="ggg" value="ggg" label="ggg" dataType="xsd:long" breakOrder=""
fieldOrder="10"/>
<element name="ggg" value="ggg" label="ggg" dataType="xsd:string" breakOrder=""
fieldOrder="11"/>
<element name="hhh" value="hhh" label="hhh" dataType="xsd:long" breakOrder=""
fieldOrder="12"/>
<element name="iii" value="iii" label="iii" dataType="xsd:string" breakOrder=""
fieldOrder="13"/>
<element name="jjj" value="jjj" label="jjj" dataType="xsd:string" breakOrder=""
fieldOrder="14"/>
</group>
</dataStructure>
</nodeList>
</output>
error message when dragging a data column into data table:
xxx
"No data found: /DATA_DS/G_1/xxx"
Thanks to Chandan Vidwani for the help,
The data types in the data set have to be changed from long to double and the error magically goes away. Long can still be used for RTF format.
I try to write custom rule in sonar (plsql) by copy xpath rule. The task of this rule is to mark 'rollback to savepoint' statement where savepoint statement is missing.
For 2 savepoint and 3 rollback statements the AST (Abstract Syntax Tree) looks like:
<PROCEDURE_DEFINITION>
...
<SAVEPOINT>
<IDENTIFIER tokenValue="SAVEPOINT" />
<IDENTIFIER tokenValue="spA" />
<SEMICOLON tokenValue=";" />
</SAVEPOINT>
...
<SAVEPOINT>
<IDENTIFIER tokenValue="SAVEPOINT" />
<IDENTIFIER tokenValue="spB" />
<SEMICOLON tokenValue=";" />
</SAVEPOINT>
...
<ROLLBACK>
<IDENTIFIER tokenValue="ROLLBACK" />
<TO />
<IDENTIFIER tokenValue="SAVEPOINT" />
<IDENTIFIER tokenValue="spB" />
<SEMICOLON tokenValue=";" />
</ROLLBACK>
...
<ROLLBACK>
<IDENTIFIER tokenValue="ROLLBACK" />
<TO />
<IDENTIFIER tokenValue="SAVEPOINT" />
<IDENTIFIER tokenValue="spA" />
<SEMICOLON tokenValue=";" />
</ROLLBACK>
...
<ROLLBACK>
<IDENTIFIER tokenValue="ROLLBACK" />
<TO />
<IDENTIFIER tokenValue="SAVEPOINT" />
<IDENTIFIER tokenValue="spX" />
<SEMICOLON tokenValue=";" />
</ROLLBACK>
...
</PROCEDURE_DEFINITION>
I search for XPath query that marks last rollback because savepoint spX is missing.
But this xpath marks last both rollbacks
//PROCEDURE_DEFINITION//ROLLBACK[
IDENTIFIER[
#tokenValue =
./ancestor::PROCEDURE_DEFINITION
//SAVEPOINT/IDENTIFIER[2]/#tokenValue
]
]
Any suggestions?
EDIT:
I found this suboptimal solution:
//PROCEDURE_DEFINITION//ROLLBACK
[
not(
./IDENTIFIER[3]/#tokenValue =
ancestor::PROCEDURE_DEFINITION//SAVEPOINT/IDENTIFIER[2]/#tokenValue
)
]
PLSQL is case insensitive. But when i add translate function, i get marked first and last ROLLBACK node. I think all rollback's names will agreed with first savepoint's name?
First of all, according to the AST you show, it seems to me that this is the PL/SQL code you want to run your XPath query on:
DECLARE
PROCEDURE foo AS
BEGIN
SAVEPOINT spA;
SAVEPOINT spB;
ROLLBACK spB; -- Compliant
ROLLBACK spA; -- Compliant
ROLLBACK spX; -- Non-Compliant
END;
BEGIN
NULL;
END;
/
When I run your first XPath query using the SSLR PL/SQL Toolkit, the rollbacks to 'spB' and 'spA' are selected, but not the one to 'spX'.
Your second XPath query selects all of them.
It seems to me that you only want to select the one to 'spX', as there is no corresponding savepoint.
A trivial change to your first query allows to reverse the selected nodes, by negating the condition using not():
//PROCEDURE_DEFINITION//ROLLBACK[
not(IDENTIFIER[
#tokenValue =
./ancestor::PROCEDURE_DEFINITION
//SAVEPOINT/IDENTIFIER[2]/#tokenValue
])
]
But I would actually recommend that you drop the PROCEDURE_DEFINITION part of the query, as SAVEPOINT and ROLLBACK statements are also valid within functions or anonymous blocks:
//ROLLBACK[not(IDENTIFIER[#tokenValue = //SAVEPOINT/IDENTIFIER[2]/#tokenValue])]