Showing posts with label xml. Show all posts
Showing posts with label xml. Show all posts

Wednesday, March 21, 2012

How to align text in a table cell?

hey, guys,

How to align text in a table cell? From the xml file, for a table cell, it has "<TextAlign>Center</TextAlign>", is there a Valign setting, like the valign in CSS or html?

There is a "VerticalAlign" style property available.

Thank you,

Nico

Monday, March 19, 2012

How to add some attributes when I use For Xml Path?

How to add some attributes when I use For Xml Path?
As I developed the sql statement using For Xml Path, the users now required
add new attributes to some tags.
For Example:
SQL:
Select TOP 2 Code, Name From City For Xml Path('City')
<City>
<Code>1</Code>
<Name>STREATOR, IL</Name>
</City>
<City>
<Code>2</Code>
<Name>LEXINGTON, GA</Name>
</City>
The new requirement and expected result as:
<City>
<Code>1</Code>
<Name Changed="N">STREATOR, IL</Name>
</City>
<City>
<Code>2</Code>
<Name Changed="N">LEXINGTON, GA</Name>
</City>
Select TOP 2 Code, 'N' as "Name/@.Changed", Name From City For Xml
Path('City')

How to add some attributes when I use For Xml Path?

How to add some attributes when I use For Xml Path?
As I developed the sql statement using For Xml Path, the users now required
add new attributes to some tags.
For Example:
SQL:
Select TOP 2 Code, Name From City For Xml Path('City')
<City>
<Code>1</Code>
<Name>STREATOR, IL</Name>
</City>
<City>
<Code>2</Code>
<Name>LEXINGTON, GA</Name>
</City>
The new requirement and expected result as:
<City>
<Code>1</Code>
<Name Changed="N">STREATOR, IL</Name>
</City>
<City>
<Code>2</Code>
<Name Changed="N">LEXINGTON, GA</Name>
</City>Select TOP 2 Code, 'N' as "Name/@.Changed", Name From City For Xml
Path('City')

Monday, March 12, 2012

How to add nodes into xml?

I want to add some nodes into xml variable:
For example:
The original xml:
<PO>
<PONO>123</PONO>
<PODATE>07252007</PODATE>
<POCNAME>ABC Company</PONAME>
<POITEMS>
...
...
</POITEMS>
<POFOOTER>No Message</POFOOTER>
</PO>
I want insert several POFEATURES node into xml as:
<PO>
<PONO>123</PONO>
<PODATE>07252007</PODATE>
<POCNAME>ABC Company</PONAME>
<POFEATURES>Special Items Mark</POFEATURES>
<POFEATURES>Special Client Mark</POFEATURES>
<POFEATURES>Credit Account</POFEATURES>
<POITEMS>
...
...
</POITEMS>
<POFOOTER>No Message</POFOOTER>
</PO>
How to use modify() to do that?
ABC wrote:

> How to use modify() to do that?
Here is an example, using a variable of type xml but you could as well
use a column of that type:
DECLARE @.x xml;
SET @.x = '<PO>
<PONO>123</PONO>
<PODATE>07252007</PODATE>
<POCNAME>ABC Company</POCNAME>
<POITEMS>
...
...
</POITEMS>
<POFOOTER>No Message</POFOOTER>
</PO>';
SET @.x.modify('
insert (
<POFEATURES>Special Items Mark</POFEATURES>,
<POFEATURES>Special Client Mark</POFEATURES>,
<POFEATURES>Credit Account</POFEATURES>
) after (PO/POCNAME)[1]
');
SELECT @.x;
Martin Honnen -- MVP XML
http://JavaScript.FAQTs.com/

How to add nodes into xml?

I want to add some nodes into xml variable:
For example:
The original xml:
<PO>
<PONO>123</PONO>
<PODATE>07252007</PODATE>
<POCNAME>ABC Company</PONAME>
<POITEMS>
..
..
</POITEMS>
<POFOOTER>No Message</POFOOTER>
</PO>
I want insert several POFEATURES node into xml as:
<PO>
<PONO>123</PONO>
<PODATE>07252007</PODATE>
<POCNAME>ABC Company</PONAME>
<POFEATURES>Special Items Mark</POFEATURES>
<POFEATURES>Special Client Mark</POFEATURES>
<POFEATURES>Credit Account</POFEATURES>
<POITEMS>
..
..
</POITEMS>
<POFOOTER>No Message</POFOOTER>
</PO>
How to use modify() to do that?ABC wrote:

> How to use modify() to do that?
Here is an example, using a variable of type xml but you could as well
use a column of that type:
DECLARE @.x xml;
SET @.x = '<PO>
<PONO>123</PONO>
<PODATE>07252007</PODATE>
<POCNAME>ABC Company</POCNAME>
<POITEMS>
..
..
</POITEMS>
<POFOOTER>No Message</POFOOTER>
</PO>';
SET @.x.modify('
insert (
<POFEATURES>Special Items Mark</POFEATURES>,
<POFEATURES>Special Client Mark</POFEATURES>,
<POFEATURES>Credit Account</POFEATURES>
) after (PO/POCNAME)[1]
');
SELECT @.x;
Martin Honnen -- MVP XML
http://JavaScript.FAQTs.com/

Wednesday, March 7, 2012

How to add an attribute to xml tags?

Source:
<row>
<col_a>5</col_a>
<col_b>7</col_b>
<col_c>9</col_c>
</row>
Target:
<row>
<col_a>5</col_a>
<col_b Changed="Y">10</col_b>
<col_c Changed="Y">11</col_c>
</row>
Is there any method(s) to add attribute(s) into xml tags as above example?
ABC wrote:

> <row>
> <col_a>5</col_a>
> <col_b Changed="Y">10</col_b>
> <col_c Changed="Y">11</col_c>
> </row>
>
> Is there any method(s) to add attribute(s) into xml tags as above example?
Yes, use the XML method modify and the insert statement:
DECLARE @.x xml;
SET @.x = '<row>
<col_a>5</col_a>
<col_b>7</col_b>
<col_c>9</col_c>
</row>';
SET @.x.modify('
replace value of (row/col_b/text())[1]
with 10
');
SET @.x.modify('
insert attribute Changed {"Y"}
into (row/col_b)[1]
');
SELECT @.x;

Martin Honnen -- MVP XML
http://JavaScript.FAQTs.com/

How to add an attribute to xml tags?

Source:
<row>
<col_a>5</col_a>
<col_b>7</col_b>
<col_c>9</col_c>
</row>
Target:
<row>
<col_a>5</col_a>
<col_b Changed="Y">10</col_b>
<col_c Changed="Y">11</col_c>
</row>
Is there any method(s) to add attribute(s) into xml tags as above example?ABC wrote:

> <row>
> <col_a>5</col_a>
> <col_b Changed="Y">10</col_b>
> <col_c Changed="Y">11</col_c>
> </row>
>
> Is there any method(s) to add attribute(s) into xml tags as above example?
Yes, use the XML method modify and the insert statement:
DECLARE @.x xml;
SET @.x = '<row>
<col_a>5</col_a>
<col_b>7</col_b>
<col_c>9</col_c>
</row>';
SET @.x.modify('
replace value of (row/col_b/text())[1]
with 10
');
SET @.x.modify('
insert attribute Changed {"Y"}
into (row/col_b)[1]
');
SELECT @.x;
Martin Honnen -- MVP XML
http://JavaScript.FAQTs.com/