none
XML Parsing - missing space RRS feed

  • Question

  • It seems to me that I have seen this discussed before but couldn't find it....

    I have some XML that I am trying to add a tag to some text.  This works great unless the situation is

    tag space tag

    in which case the intervening space is lost.  The method used to add the tag is to convert the XML to a string, find the position of the text I want to tag, and place the tag around it.  Once that is done I parse the XML.

    Here is a extremely simplified version of what I am doing that illustrates the issue.

            Dim xe As XElement
            xe = <p>Test<s>*</s> 123.456</p>
            Dim xevB As String = xe.Value 'xe value before - Test* 123.456
            Dim sm As String = "<p>Test<s>*</s> <e>123.456</e></p>"
            xe = XElement.Parse(sm)
            Dim xevA As String = xe.Value 'xe value after - Test*123.456  note missing space after *
            Stop

    I do have a work around for the particular situation I am working on, but it is specific.  Any Ideas / suggestions are appreciated.

    Thanks.


    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it."

    - from former MSDN User JohnWein

    SerialPort Info

    Multics - An OS ahead of its time.

    Thursday, August 30, 2018 12:02 PM

All replies

  • Perhaps placing the following code in the place of a space.

    Dim xe As XElement
    xe = <p>Test<s>*</s> 123.456</p>
    Dim xevB As String = xe.Value 'xe value before - Test* 123.456
    Dim sm As String = Regex.Unescape("<p>Test<s>*</s>&#160;<e>123.456</e></p>")
    xe = XElement.Parse(sm)
    Dim xevA As String = xe.Value


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, August 30, 2018 12:18 PM
    Moderator
  • Perhaps placing the following code in the place of a space.

    Dim xe As XElement
    xe = <p>Test<s>*</s> 123.456</p>
    Dim xevB As String = xe.Value 'xe value before - Test* 123.456
    Dim sm As String = Regex.Unescape("<p>Test<s>*</s>&#160;<e>123.456</e></p>")
    xe = XElement.Parse(sm)
    Dim xevA As String = xe.Value


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Great minds...  In one of my tests I did that and the NBSP came through and the string looked correct. 

    I'd have to test all the systems that depend on the data to make certain that it doesn't break them.  IT is changing the datat.


    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it."

    - from former MSDN User JohnWein

    SerialPort Info

    Multics - An OS ahead of its time.

    Thursday, August 30, 2018 3:34 PM
  • How about:

      xe = XElement.Parse(sm, LoadOptions.PreserveWhitespace)     


    Thursday, August 30, 2018 7:31 PM
  • How about:

      xe = XElement.Parse(sm, LoadOptions.PreserveWhitespace)     


    Tried that one also.  It might work in the example but using the actual data it creates a huge problem.  Here is a sample of the real data(where I found this)

    <sdivs>
      <sd d="1">Notwithstanding the provisions of section <eref>1.140</eref> to the contrary, the provisions of sections <eref>32.087</eref>, <eref>144.020</eref>, <eref>144.021</eref>, <eref>144.069</eref>, <eref>144.071</eref>, <eref>144.440</eref>, <eref>144.450</eref>, <eref>144.455</eref>, <eref>144.525</eref>, <eref>144.610</eref>, <eref>144.613</eref>, and <eref>144.615</eref>, as amended by this act<sup>*</sup>, shall be nonseverable, and if any provision is for any reason held to be invalid, such decision shall invalidate all of the remaining provisions of sections<sup>**</sup><eref> 32.087</eref>, <eref>144.020</eref>, <eref>144.021</eref>, <eref>144.069</eref>, <eref>144.071</eref>, <eref>144.440</eref>, <eref>144.450</eref>, <eref>144.455</eref>, <eref>144.525</eref>, <eref>144.610</eref>, <eref>144.613</eref>, and <eref>144.615</eref>, as amended by this act<sup>*</sup>.</sd>
    </sdivs>

    Find the double ** and the following tag has the fix.

    You can see it on our web site here

    RSMo 144.008



    "Those who use Application.DoEvents() have no idea what it does and those who know what it does never use it."

    - from former MSDN User JohnWein

    SerialPort Info

    Multics - An OS ahead of its time.

    Thursday, August 30, 2018 9:18 PM
  • Hi,

    Do you resolve the issue? If you resolve the issue, could you please mark the helpful as answer. it will be beneficial to other community.

    Best Regards,

    Alex


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, September 6, 2018 6:42 AM