Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic DOORS (steve huntington)
Decrease font size
Increase font size
Topic Title: RegExps for XML
Topic Summary:
Created On: 6-Apr-2006 15:52
Status: Post and Reply
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Quick Reply Quick Reply
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
Answer This question was answered by Tony Goodman, on Tuesday, April 11, 2006 11:44 AM

Answer:
I use MSXML to do all my XML processing and I recommend this approach rather than trying to parse the text yourself.
MSXML takes care of escaping special characters automatically and gives you the ability to loop through collections of nodes etc.

You can find out more here.
 6-Apr-2006 15:52
User is offline View Users Profile Print this message


Richard Good

Posts: 152
Joined: 22-Mar-2005

Hi All,
Probably having a bit of Brain fade in regard to using RegExps to get at the information within my variation of xml. What I want to do is store information in a module attribute in XML format (generated by a dialog box) then use that information to create my variant of traceability testing. I am having trouble formatting Regexps to extract the information mostly because "*" and "+" are always greedy and find the last occurrence rather than the first. Thought I would ask if any of you DXL Gurus out there had solved this extremely annoying problem ie formulated a regexp to find the first occurrence not the last.

The following is an example of what might be in one of my module level text atttributes

"<rec><src>/SomeModule</src><path>/FirstModToTraceThrough#/SecondModToTraceTrough#...</path><attName>AttributeToCreate</attName><atts>lots of information about what to get
including many carriage returns etc
</atts></rec>
<rec>
same sort of stuff as above
</rec>
<rec>
</rec>
..."

At the moment I frig it by using characters that I hope!! will not appear in the module level attribute
and by finding the relevant record first and only querying on that (note the differrent character in the FindRec regexp). This works, but if I extend this to a few more levels as I want to in a differrent variant then I will soon run out of uncommon characters, and I want to do it properly anyway!

Regexp FindRec = regexp "<rec>([^~]*)~</rec>"
Regexp FindSrc = regexp "<src>([^¬]*)¬</src>"
Regexp FindPath =regexp "<path>([^¬]*)¬</path>"
Regexp FindAttName= regexp "<attName>([^¬]*)¬</attName>"
Regexp FindAttStr= regexp "<atts>([^¬]*)¬</atts>"
Regexp FindLink= regexp "<link>([^¬]*)¬</link>"
Regexp FindOptions = regexp "<options>([^¬]*)¬</options>"

I know there are several other ways to skin this particular cat ie functions (time consuming unless of course someone has some to share.) or storing the information in a module (ugly).

Cheers for any Help/ Observations.

-------------------------
Regards,

Richard Good
Report this to a Moderator Report this to a Moderator
 6-Apr-2006 21:23
User is offline View Users Profile Print this message


Shawn Stepper

Posts: 96
Joined: 6-Aug-2004

The attached code goes through all the data in a buffer full of XML and populates a Skip list with the tag names and tag contents. This is specific to an application of mine, but you shouldn't have to change it much.

Shawn

-------------------------
Shawn Stepper
shawn.e.stepper@wellsfargo.com
Report this to a Moderator Report this to a Moderator
 7-Apr-2006 10:40
User is offline View Users Profile Print this message


Iftakher Uddin

Posts: 56
Joined: 16-Sep-2004

The attach code will return the given tag (first position) and it contents :

Greetings,

Rony

===================
Iftakher Uddin (Rony)
Iftakher.Uddin@HOOD-Group.com
Report this to a Moderator Report this to a Moderator
 7-Apr-2006 15:28
User is offline View Users Profile Print this message


Tony Goodman

Posts: 1098
Joined: 12-Sep-2002

Answer Answer
I use MSXML to do all my XML processing and I recommend this approach rather than trying to parse the text yourself.
MSXML takes care of escaping special characters automatically and gives you the ability to loop through collections of nodes etc.

You can find out more here.

-------------------------
Tony Goodman
http://www.smartdxl.com
Report this to a Moderator Report this to a Moderator
 10-Apr-2006 09:57
User is offline View Users Profile Print this message


Iftakher Uddin

Posts: 56
Joined: 16-Sep-2004

Yes, thats true and its much faster. To navigate the XML; XPath queries can be used which is a very effcient and powerful way to query.

Greetings,

Rony

===================
Iftakher Uddin (Rony)
Iftakher.Uddin@HOOD-Group.com
Report this to a Moderator Report this to a Moderator
 10-Apr-2006 20:18
User is offline View Users Profile Print this message


Richard Good

Posts: 152
Joined: 22-Mar-2005

Tony, Rony, Shawn,

Thanks for the suggestions. Tony: I tried the xml approach, downloaded the SDK/documentation for the MSXML4.dll from microsoft, tried to do myself a little vbs script and a javascript. Failed miserably to get anything working at all despite 2 or 3 hours of trying various things. I'm obviously missing a trick somwhere, do you have some sort of example that uses MSXML and DOORS that'd get me orbiting somwhere round the earth, think I'm out by Pluto at the moment.

-------------------------
Regards,

Richard Good
Report this to a Moderator Report this to a Moderator
 11-Apr-2006 11:41
User is offline View Users Profile Print this message


Richard Good

Posts: 152
Joined: 22-Mar-2005

Cheers for the tip Tony: this technique may be very useful to me
Got over my brain fade and did a nice little example: see below (I have also attached the xml file that goes with the dxl)

-------------------------
Regards,

Richard Good
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic DOORS forum.
There are currently 1 users logged in.
The most users ever online was 15 on 15-Jan-2009 at 16:36.
There are currently 0 guests browsing this forum, which makes a total of 1 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.