faqts : Computers : Programming : Languages : Tse : XML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

TSE: XML: Parse: How to mark a block of text in a single XML tag?

Dec 19th, 2004 15:13
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 19 December 2004 - 04:32 am -------------------

TSE: XML: Parse: How to mark a block of text in a single XML tag?

---

Informal Backus Naur Form:

 -(<)-[name]-(>)-[text]-(<)-(/)-[name]-(>)-

---

Description:

 First you get a '<'

 Then you get a name

 Then you get a '>'

 Then you get possibly some text

 Then you get a '<'

 Then you get a '/'

 Then you get a name

 Then you get a '>'

---
---

Method:

 You first search the begin tag, and note the coordinates of its
 position

 You then search the corresponding end tag, and note the coordinates of
 its position

 You then mark the block between this begin and end positions

 That will contain your text

---
---

Steps: Overview:

 1. -Create a single tag

--- cut here: begin --------------------------------------------------

<test>


   this is a text




   </test>

--- cut here: end ----------------------------------------------------

 2. -Mark this single tag block

 3. -Run this macro

     1. It checks if a block is marked

     2. It then skips possible spaces in the begin of the block

     3. It then checks if a '<' is found

     4. It then gets the name of the tag

     5. It then checks if a '>' is found

     6. It stores the begin position

     7. It then searches for the end tag

     8. It stores the end position

     9. It finally marks the block of text between begin and
        end position

--- cut here: begin --------------------------------------------------

FORWARD INTEGER PROC FNBlockCheckMarkXmlSingleB()

FORWARD PROC Main()

// --- MAIN --- //

PROC Main()

 Message( FNBlockCheckMarkXmlSingleB() ) // gives e.g. TRUE if the 
text between a single begin tag and end tag can be marked

END

<F12> Main()

// --- LIBRARY --- //

// library: block: check: xml: single (no nested xml, only 1 tag with 
text in between, e.g. '<test> this is a text </test>') 
(filenamemacro=checblxs.s) [kn, ri, su, 19-12-2004 03:25:25]

INTEGER PROC FNBlockCheckMarkXmlSingleB()

 // e.g. PROC Main()

 // e.g.  Message( FNBlockCheckMarkXmlSingleB() ) // gives e.g. TRUE 
if the text between a single begin tag and end tag can be marked

 // e.g. END

 // e.g.

 // e.g. <F12> Main()

 STRING nameS[255] = ""

 STRING tagendS[255] = ""

 INTEGER x1 = 0

 INTEGER y1 = 0

 INTEGER x2 = 0

 INTEGER y2 = 0

 //

 IF NOT ( IsBlockInCurrFile() )

  Warn( "XML: Error: Please mark a block first" )

  RETURN( FALSE )

 ENDIF

 //

 GotoBlockBegin() // goto the beginning of the marked block

 //

 LFind( "[ ]@\c", "ixl" ) // skip spaces

 //

 IF NOT ( CurrChar() == Asc( "<" ) ) // check if found the '<' of 
begin tag

  Warn( "XML: Error: No begin tag '<' found in XML block" )

  RETURN( FALSE )

 ENDIF

 //

 NextChar() // current character processed, so skip it and goto next 
character

 //

 IF NOT LFind( "[a-zA-Z][a-zA-Z0-9]@\c", "ixl" ) // get name of begin 
tag and skip it

  Warn( "XML: Error: No begin tag name found in XML block" )

  RETURN( FALSE )

 ENDIF

 //

 nameS = GetFoundText() // get the found tag name

 //

 IF NOT( CurrChar() == Asc( ">" ) ) // check if found the '>' of begin 
tag

  Warn( "XML: Error: No begin tag '>' found in XML block" )

  RETURN( FALSE )

 ENDIF

 //

 NextChar() // current character processed, so skip it and goto next 
character

 //

 x1 = CurrCol() // get the x-coordinate of the beginning of the text

 y1 = CurrLine() // get the y-coordinate of the beginning of the text

 //

 tagendS = "<" + "/" + nameS + ">"

 //

 IF NOT LFind( tagendS, "l" ) // search for end tag (skipping 
over any other text in between possibly over several lines, and 
implicitely putting the cursor on first '<')

  Warn( "No" + " " + tagendS + " " + "found in XML block" )

  RETURN( FALSE )

 ENDIF

 //

 PrevChar() // be sure to goto the position before the '<' of the end 
tag

 //

 x2 = CurrCol() // get the x-coordinate of the end of the text

 y2 = CurrLine() // get the y-coordinate of the end of the text

 //

 IF NOT ( ( ABS ( x2 - x1 ) == 1 ) AND ( ABS ( y2 - y1 ) == 0 ) ) // 
if text of more than 1 character mark it, else do not mark (it says 
here if only 1 character difference, that is (x2-x1=1), and on the 
same line (that is (y2-y1=0), you have here no text between the tags, 
e.g. '<test></test>')

  GotoColumn( x1 ) // goto coordinates of beginning of the text

  GotoLine( y1 )

  //

  MarkStream() // mark from the begin of the text

  //

  GotoColumn( x2 ) // goto coordinates of end of the text

  GotoLine( y2 )

  //

  MarkStream() // mark (and fix) to the end of the text

  //

 ELSE

  UnMarkBlock() // if no text unmark block (to indicate no text found)

 ENDIF

 //

 RETURN( TRUE )

 //

END

--- cut here: end ----------------------------------------------------

---
---

Internet: see also:

---

TSE: XML: Parser: Link: Overview: Can you give me an overview of links?
http://www.faqts.com/knowledge_base/view.phtml/aid/32677/fid/1734

----------------------------------------------------------------------