Skip to main content
Hi,

 

I am working on Win7 Machine with 8Gb RAM.

 

While creating an XML from a shapefile, comments are being generated automatically which I want to remove. Tried XMLFormatter and StringReplacer, but didn't get the desired output. Can someone help me with that (:

 

(The rows inside the box are automaticallygenerated and should be removed)

 

Hi,

 

 

I think the StringRepalcer can do that.

 

Text to Match: <&\\?/]?(xml|fme:)m^<]+>\\n?

 

Replacement Text: <blank>

 

Use Regular Expressions: yes

 

 

... but those lines are parts of the XML document, not comments. The resultant text may not be a valid XML document no longer.

 

Why do you need to remove them?

 

 

Takashi

 

 
Hi Takashi,

 

 

I tried using StringReplacer. But since, those comments are not a part of any XML Schema, those cannot be found using StringReplacer. 

 

I need to remove those comments as I have to convert those XMLs to some other internal format. Cna't there be any other option ):
I supposed that the XML document has been read by the Text File reader. Was my supposition wrong?
Hi,

 

 

how about reading the XML file using the Text File reader, followed by a StringReplacer:

 

 

Text to Match: (?s)<!--.*?-->

 

 

Then write it out with the Text File writer again.

 

 

There are also a few command line tools that can do it for you, have a look here for more options: http://stackoverflow.com/questions/1464697/stripout-comments-from-xml

 

 

David

Hi,

@Takashi: No, I am not using Text file Reader. 

 

@David: I tried using XML Textfile Reader, nothing was shown in o/p.

 

I think something can be done in o/p parameters using Navigator bar.
As David suggested, it seems that Text File reader -> StringReplacer -> Text File writer is quick way. Is there a reason that the Text File reader/writer cannot be used?

I am not sure about how to do it.

 

Do I need to run two WBs for that. One for Shp to txt and other for txtto xml?

 

How Exactly to go about it?
XML is a kind of text. You can read/write simply an XML document with the Text File reader/writer.

 

Since you've already created the xml file with a workspace (shp to xml), you don't need to touch it.

 

Create another workspace (xml to xml):

 

- read the xml file with the Text File reader,

 

- remove unnecessary parts with the StringReplacer,

 

- write the resulting text with the Text File writer.
Just be aware that you may have to set encoding of the Text File writer to the same one that is declared in the first line of the XML.

 

<?xml version="1.0" encoding="UTF-8"?>

 

 

oops, you are going to remove it (screenshot). If you removed it, the text is not an XML document no longer.

 

You really need to remove it?

Hah !!! 😛  Thank you all.

 

I tried running two WBs

 

1) shp to txt

 

2) txt to xml

 

And it is working perfectly. Using StringReplacer, it is doing exactly the way I wanted. The only issue left now is there are empty lines coming in place  of comments.

Hi,

 

Thank you all for your ideas :)

 

I tried using Tester with operator 'Attribute Is Empty' and it worked (with correct parcing).

StringSearcher can also be used with ^$ to find empty rows.

 

http://fmepedia.safe.com/AnswersQuestionDetail?id=906a0000000csytAAA

Reply