Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consecutive spaces in xml text value are collapsed into a single one #9

Open
amnonkhen opened this issue Jun 12, 2017 · 2 comments
Open

Comments

@amnonkhen
Copy link

amnonkhen commented Jun 12, 2017

The 2 spaces in the value of the a element in x y are squashed into a single space.

@Test
public void test_multiple_spaces() throws ParseException, XPathParseException, NavException, XPathEvalException {
    VTDGen vtdGen = new VTDGen();
    // notice the 2 spaces
    String expectedValue = "x  y";
    vtdGen.setDoc(("<a>" + expectedValue + "</a>").getBytes());
    vtdGen.parse(true);  // set namespace awareness to true
    VTDNav vn = vtdGen.getNav();
    AutoPilot ap = new AutoPilot(vn);
    ap.selectXPath("//a");
    String actualValue = null;
    int result = -1;
    result = ap.evalXPath();
    if (result != -1) {
        int t = vn.getText();
        if (t != -1)
            actualValue =  vn.toNormalizedString(t);
    }
    Assert.assertEquals(expectedValue, actualValue);
}

The code for reading the value using xpath is taken from the code samples page

@amnonkhen
Copy link
Author

amnonkhen commented Jun 12, 2017

I just saw in the javadoc of toNormalizedString that space collapsing is the intended behavior.
I realized that using toNormalizedString2 instead of toNormalizedString the bug does not happen.
What is the difference between the two?

@amnonkhen amnonkhen changed the title consecutive spaces in xml text value are squashed into a single one consecutive spaces in xml text value are collapsed into a single one Jun 12, 2017
@jzhang2004
Copy link
Owner

toString is the one you should consider using if you don't want collapsed space... toRawString would even conserve character/built-in entities...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants