• How to import an XML file into Word

    Author
    Topic
    #468656

    Hi all,

    How do you import an XML file into Word?

    Each entry has a Name and a Summary text field.

    I want to be able to remove the tabs, but keep the structure. So I want to preserve those two field names as Heading levels or style names so I can process them afterwards, using Find+Replace.

    TIA

    – avi

    Viewing 6 reply threads
    Author
    Replies
    • #1221927

      Avi,

      First off, which version of Word are you working in?

      If you’re working in a version prior to Word 2007, you could open a blank document and then use Insert > File to insert the content of the xml file, into the Word document.

      You could create custom paragraph styles for ‘Name’ and ‘Summary’, and then using Find/Replace, search for example for “” and in the replace field, just specify the ‘Name’ style. Do the same for ‘Summary’.
      Then change the replace field to ‘No formatting’, and do a series of find/replaces to get rid of text like “” and “”, as well as the extra tabs.

      This would leave you with just the text entries, each associated with an identifying style.

      Gary

      • #1221935

        Thanks for the response!

        Using Word 2003.

        Ok, I tried it. I see all the pink summary tabs.

        E.g.,

        <

        >

        where
        <

        > is pink
        and “Gets or sets the application.” is black.

        See attachment.

        I could not grab the summary tags by a Find. Maybe there is a special Find character or Find setting that I am suppsed to set?

        Thanks,

        – avi

        Avi,

        First off, which version of Word are you working in?

        If you’re working in a version prior to Word 2007, you could open a blank document and then use Insert > File to insert the content of the xml file, into the Word document.

        You could create custom paragraph styles for ‘Name’ and ‘Summary’, and then using Find/Replace, search for example for “” and in the replace field, just specify the ‘Name’ style. Do the same for ‘Summary’.
        Then change the replace field to ‘No formatting’, and do a series of find/replaces to get rid of text like “” and “”, as well as the extra tabs.

        This would leave you with just the text entries, each associated with an identifying style.

        Gary

    • #1221941

      avi,

      Are you sure you’re working in Word 2003? – those pink xml tags look like what you get in Word 2007.

      See attached shot for what I’m seeing in Word 2003.

      I’m not sure offhand how to do the equivalent in Word 2007, but will check once I can get over to a PC with 2007 on it.

      Gary

    • #1221944

      Just a followup:

      If you do an Insert > File of an XML file in Word 2007 (you may need to add the Insert > File command to the QAT), you get the result as illustrated below.

      Let me know which version of Word you’re using and what commands you’re using to import the XML, thanks.

      Gary

      • #1221963

        Ok, I just tried it with Word 2007. Insert > File of an XML file.
        Still get the pink tabs.

        Maybe there is another viewing mode I should be using?

        – avi

        Just a followup:

        If you do an Insert > File of an XML file in Word 2007 (you may need to add the Insert > File command to the QAT), you get the result as illustrated below.

        Let me know which version of Word you’re using and what commands you’re using to import the XML, thanks.

        Gary

    • #1221946

      Yet another followup:

      You get the pink XML brackets (in both Word 2003 and Word 2007) if you do a direct File > Open on the XML file.

      I’m not versed in manipulating XML that’s in an XML file that’s directly opened in Word, but I wouldn’t expect there to be many options to manipulate the file, because it is an XML file and needs to remain structured in a very specific way – what you’re seeing when you directly open an XML file in Word is more of a visual representation of the data. It looks like you may be able to apply an XSLT to it to affect the view of the data, but I can’t provide any guidance on that.

      In any case, if you do a File > Insert, you’ve then got the XML data in a regular Word document, and you can then transform it via Find/Replace.

      Gary

    • #1221954

      I can also try Word 2007. I own that also.

      >> In any case, if you do a File > Insert,

      I assume you mean ‘ Insert > File ‘ 🙂

      >> Let me know which version of Word you’re using and what commands you’re using to import the XML, thanks.

      I did use ‘ Insert > File ‘ – and got the pink tags.

      tnx

      avi

    • #1221992

      Yep, I meant ‘File > Insert’, thanks. 😉

      What happens if you try the following in Word 2007:

      Open new empty document.
      On the Insert tab, in the Text group, click on the down arrow to the right of ‘Object’, click on ‘Text from file’, navigate to your XML file, and click on insert.

      When I try it here, I get plain text with tabs, and not the pink XML markers.

      Gary

    • #1222020

      XML is essentially a database format stored in a flat ASCII file. If you open it with a text editor or with Word as Gary suggests then you can see everything in the file with no formatting. Editing this flat text is easy enough but you need to ensure that you don’t break the xml so that it remains ‘well formed”.

      The way you have opened the file has parsed the data into its elements but you have not chosen a way to display the data. This is done by associating an XSL transformation with the xml data. This allows you to view the data lots of different ways. For example, one view might show only the assemblyname elements arranged in alphabetical order followed by the membersmembersummary elements. Another view might show the membersmembersummary elements as bulleted text under a heading. Without seeing the complete xml file or the schema on which it is based, we can only guess at how you might want to view the data.

      I think an easier way for you to view and edit your data is to use Microsoft Excel which will open the xml in a tabular way.

      Suggestion: Looking at your brief screen capture of the xml, the data doesn’t look particularly well designed. The members element is independent of the assembly element although the names and line order does suggest a relationship. Positioning the tags adjacent to each other does not create a relationship in xml (although it does with words on a page). If this data is actually related then you need to structure it that way. For example, the following nests the members as part of an assembly.

      Code:
      	
      		ABC.BagsArranger
      		
      			
      				Gets or sets the application
      			
      			
      				Occurs after the view changed its visibility state.
      			
      		
      	
      

      A good place to start if you still want to pursue this XSL transformation of your XML data is this article by Bill Coan http://msdn.microsoft.com/en-us/library/aa159901%28office.11%29.aspx.

      • #1222164

        Hi Andrew, Thanks for giving me your time on this.

        Tnx for your comment about the design of the XML.
        You made me read it. I did not write the XML. I am sorry about this but now I read for the first time and I see that Word had apparently trashed some of the clauses.
        So now I just loaded it into NotePad and here is the code below. In each clause ‘member name’ is the name of a member (property, method, or event) of a class, and ‘summary’ is a brief description of what the member does.

        I could now simply load it into Word as ascii text and do successive Find+Replaces to get just the ‘member name’ + ‘summary’, but I was wondering if there was an easy way to parse this so I get a nice table of something.

        >> I think an easier way for you to view and edit your data is to use Microsoft Excel which will open the xml in a tabular way.

        Just tried that. Thanks! I get an enormous table. That does it! I can move on from there.

        Great thanks,

        – avi

        Code:
        
            
                ABC.BagsArrangerUI
            
            
                
                    
                    Gets or sets the application.
                    
                
                
                    
                    Occures after the view changed its visibility state.
                    
                
                
                    
                    Occures after the view changed its active state.
                    
                
                
                    
                    Gets or sets a value indicating whether the view is visible.
                    
                
                
                    
                    Gets or sets a value indicating whether the view is active.
                    NOTE: In case the view is not active it means it will not be visible and the user
                    will not be able to make it visible from the ToolBar.
                    
                
                
        
    Viewing 6 reply threads
    Reply To: How to import an XML file into Word

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: